01 Jul 2019 01:45:53 UTC
- Distribution: Algorithm-Backoff
- Module version: 0.009
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Testers (2255 / 0 / 9)
- KwaliteeBus factor: 1
- 94.27% Coverage
- License: perl_5
- Perl: v5.10.1
- Activity24 month
- Download (22.89KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version
- SEE ALSO
- COPYRIGHT AND LICENSE
Algorithm::Backoff - Various backoff strategies for retry
This document describes version 0.009 of Algorithm::Backoff (from Perl distribution Algorithm-Backoff), released on 2019-06-20.
# 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, timestamp is # optional but must be monotonically increasing. my $secs = $ab->failure(); # => 2 my $secs = $ab->success(); # => 0 my $secs = $ab->failure(); # => 2
This distribution provides several classes that implement various backoff strategies for setting delay between retry attempts.
This class (
Algorithm::Backoff) is a base class only.
new(%args) -> obj
This function is not exported.
Arguments ('*' denotes required arguments):
jitter_factor => 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.
max_attempts => 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.
Return value: (obj)
my $secs = $obj->success([ $timestamp ]);
Log a successful attempt. If not specified,
$timestampdefaults to current time. Will return the suggested number of seconds to wait before doing another attempt.
my $secs = $obj->failure([ $timestamp ]);
Log a failed attempt. If not specified,
$timestampdefaults to current time. 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_attemptsparameter has been exceeded).
Please visit the project's homepage at https://metacpan.org/release/Algorithm-Backoff.
Source repository is at https://github.com/perlancar/perl-Algorithm-Backoff.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Algorithm-Backoff
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Retry::Backoff - an application of Algorithm::Backoff to retry a piece of code using various backoff strategies.
App::AlgorithmBackoffUtils - various CLI's related to Algorithm::Backoff.
Action::Retry - Somehow I didn't find this module before writing Algorithm::Backoff. Otherwise I probably would not have created Algorithm::Backoff. But Algorithm::Backoff offers an alternative interface, some additional parameters (like delay on success and jitter factor), a lighter footprint (no Moo), and a couple more strategies.
This software is copyright (c) 2019 by firstname.lastname@example.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Algorithm::Backoff, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Algorithm::Backoff
For more information on module installation, please visit the detailed CPAN module installation guide.