Retry::Backoff - Retry a piece of code, with backoff strategies
This document describes version 0.001 of Retry::Backoff (from Perl distribution Retry-Backoff), released on 2019-06-18.
use Retry::Backoff 'retry'; # by default, will use Algorithm::Backoff::Exponential with these parameters: # - initial_delay = 1 (1 second) # - max_delay = 300 (5 minutes) # - max_attempts = 10 retry { ... }; # pick backoff strategy (see corresponding Algorithm::Backoff::* for # list of parameters) retry { ... } strategy=>'Constant', delay=>1, max_attempts=>10; #
This module provides "retry" to retry a piece of code if it dies. Several backoff (delay between retries) strategies are available from Algorithm::Backoff:: modules.
Algorithm::Backoff
Usage:
retry { attempt-code... } %args;
Retry the attempt-code if it dies. Known arguments:
strategy
String. Default is Exponential (with initial_delay=1, max_delay=300, and max_attempts=10).
Exponential
initial_delay
max_delay
max_attempts
on_success
Coderef. Will be called if attempt-code is deemed as successful.
on_failure
Coderef. Will be called if attempt-code is deemed to have failed.
retry_if
Coderef. If not specified, attempt-code is deemed to have failed if it dies. If this is specified, then the coderef will be called and if it returns true then the attempt-code is deemed to have failed.
Coderef will be passed:
\%h
containing these keys:
error action_retry attempt_result attempt_parameters
non_blocking
Boolean.
The rest of the arguments will be passed to the backoff strategy module (Algorithm::Backoff::*).
Algorithm::Backoff::*
Please visit the project's homepage at https://metacpan.org/release/Retry-Backoff.
Source repository is at https://github.com/perlancar/perl-Retry-Backoff.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Retry-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.
Code is based on Action::Retry.
Other similar modules: Sub::Retry, Retry.
Backoff strategies are from Algorithm::Backoff::* modules.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2019 by perlancar@cpan.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.
To install Retry::Backoff, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Retry::Backoff
CPAN shell
perl -MCPAN -e shell install Retry::Backoff
For more information on module installation, please visit the detailed CPAN module installation guide.