Algorithm-Backoff
view release on metacpan or search on metacpan
lib/Algorithm/Backoff/Constant.pm view on Meta::CPAN
successes):
% show-backoff-delays -a Constant --delay 2 \
0 0 0 0 0 1 1 1
2
2
2
2
2
0
0
0
=head1 DESCRIPTION
This backoff strategy is one of the simplest: it waits X second(s) after each
failure, or Y second(s) (default 0) after a success. There are limits on the
number of attempts (`max_attempts`) and total duration (`max_actual_duration`).
Some randomness can be introduced to avoid "thundering herd problem".
=head1 METHODS
=head2 new
Usage:
new(%args) -> obj
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<consider_actual_delay> => I<bool> (default: 0)
Whether to consider actual delay.
If set to true, will take into account the actual delay (timestamp difference).
For example, when using the Constant strategy of delay=2, you log failure()
again right after the previous failure() (i.e. specify the same timestamp).
failure() will then return ~2+2 = 4 seconds. On the other hand, if you waited 2
seconds before calling failure() again (i.e. specify the timestamp that is 2
seconds larger than the previous timestamp), failure() will return 2 seconds.
And if you waited 4 seconds or more, failure() will return 0.
=item * B<delay>* => I<ufloat>
Number of seconds to wait after a failure.
=item * B<delay_on_success> => I<ufloat> (default: 0)
Number of seconds to wait after a success.
=item * B<jitter_factor> => I<float>
How much to add randomness.
If you set this to a value larger than 0, the actual delay will be between a
random number between original_delay * (1-jitter_factor) and original_delay *
(1+jitter_factor). Jitters are usually added to avoid so-called "thundering
herd" problem.
The jitter will be applied to delay on failure as well as on success.
=item * B<max_actual_duration> => I<ufloat> (default: 0)
Maximum number of seconds for all of the attempts (0 means unlimited).
If set to a positive number, will limit the number of seconds for all of the
attempts. This setting is used to limit the amount of time you are willing to
spend on a task. For example, when using the Exponential strategy of
initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If
failures are logged according to the suggested delays, and max_actual_duration
is set to 21 seconds, then the third failure() will return -1 instead of 24
because 3+6+12 >= 21, even though max_attempts has not been exceeded.
=item * B<max_attempts> => I<uint> (default: 0)
Maximum number consecutive failures before giving up.
0 means to retry endlessly without ever giving up. 1 means to give up after a
single failure (i.e. no retry attempts). 2 means to retry once after a failure.
Note that after a success, the number of attempts is reset (as expected). So if
max_attempts is 3, and if you fail twice then succeed, then on the next failure
the algorithm will retry again for a maximum of 3 times.
=item * B<max_delay> => I<ufloat>
Maximum delay time, in seconds.
=item * B<min_delay> => I<ufloat> (default: 0)
Maximum delay time, in seconds.
=back
Return value: (obj)
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/Algorithm-Backoff>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-Algorithm-Backoff>.
=head1 SEE ALSO
L<Algorithm::Backoff>
Other C<Algorithm::Backoff::*> classes.
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 CONTRIBUTING
( run in 1.212 second using v1.01-cache-2.11-cpan-5b529ec07f3 )