Algorithm-Backoff

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

     # 1. pick a strategy and instantiate

     use Algorithm::Backoff::Constant;
     my $ab = Algorithm::Backoff::Constant->new(
         delay             => 2, # required
         #delay_on_success => 0, # optional, default 0
     );

     # 2. log success/failure and get a new number of seconds to delay. if you don't
     # want to log for the current time, you can pass a timestamp (number of seconds
     # passed since some reference value, like a Unix epoch) as the argument, which
     # should be monotonically increasing.

     my $secs = $ab->failure(); # => 2
     my $secs = $ab->success(); # => 0
     my $secs = $ab->failure(); # => 2

DESCRIPTION
    This distribution provides several classes that implement various
    backoff strategies for setting delay between retry attempts.

README  view on Meta::CPAN

        retry again for a maximum of 3 times.

    Return value: (obj)

  success
    Usage:

     my $secs = $obj->success([ $timestamp ]);

    Log a successful attempt. If not specified, $timestamp defaults to
    current Unix timestamp. Will return the suggested number of seconds to
    wait before doing another attempt.

  failure
    Usage:

     my $secs = $obj->failure([ $timestamp ]);

    Log a failed attempt. If not specified, $timestamp defaults to current
    Unix timestamp. Will return the suggested number of seconds to wait
    before doing another attempt, or -1 if it suggests that one gives up
    (e.g. if "max_attempts" parameter has been exceeded).

HOMEPAGE
    Please visit the project's homepage at
    <https://metacpan.org/release/Algorithm-Backoff>.

SOURCE
    Source repository is at
    <https://github.com/perlancar/perl-Algorithm-Backoff>.

lib/Algorithm/Backoff.pm  view on Meta::CPAN

 # 1. pick a strategy and instantiate

 use Algorithm::Backoff::Constant;
 my $ab = Algorithm::Backoff::Constant->new(
     delay             => 2, # required
     #delay_on_success => 0, # optional, default 0
 );

 # 2. log success/failure and get a new number of seconds to delay. if you don't
 # want to log for the current time, you can pass a timestamp (number of seconds
 # passed since some reference value, like a Unix epoch) as the argument, which
 # should be monotonically increasing.

 my $secs = $ab->failure(); # => 2
 my $secs = $ab->success(); # => 0
 my $secs = $ab->failure(); # => 2

=head1 DESCRIPTION

This distribution provides several classes that implement various backoff
strategies for setting delay between retry attempts.

lib/Algorithm/Backoff.pm  view on Meta::CPAN

Return value:  (obj)


=head2 success

Usage:

 my $secs = $obj->success([ $timestamp ]);

Log a successful attempt. If not specified, C<$timestamp> defaults to current
Unix timestamp. Will return the suggested number of seconds to wait before doing
another attempt.

=head2 failure

Usage:

 my $secs = $obj->failure([ $timestamp ]);

Log a failed attempt. If not specified, C<$timestamp> defaults to current Unix
timestamp. Will return the suggested number of seconds to wait before doing
another attempt, or -1 if it suggests that one gives up (e.g. if C<max_attempts>
parameter has been exceeded).

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Algorithm-Backoff>.

=head1 SOURCE



( run in 0.978 second using v1.01-cache-2.11-cpan-df04353d9ac )