Algorithm-Backoff-RetryTimeouts
view release on metacpan or search on metacpan
NAME
Algorithm::Backoff::RetryTimeouts - A backoff-style retry algorithm
with adjustable timeout support
VERSION
version v1.0.0
SYNOPSIS
use Algorithm::Backoff::RetryTimeouts;
my $retry_algo = Algorithm::Backoff::RetryTimeouts->new(
# common adjustments (defaults shown)
max_attempts => 8,
max_actual_duration => 50,
jitter_factor => 0.1,
timeout_jitter_factor => 0.1,
adjust_timeout_factor => 0.5,
min_adjust_timeout => 5,
# other defaults
initial_delay => sqrt(2),
exponent_base => sqrt(2),
delay_on_success => 0,
min_delay => 0,
max_delay => undef,
consider_actual_delay => 1,
);
my ($delay, $timeout);
$timeout = $retry_algo->timeout;
my $is_successful = 0;
while (!$is_successful) {
$actionee->timeout( $timeout );
$is_successful = $actionee->do_the_thing;
($delay, $timeout) = $is_successful ? $retry_algo->success : $retry_algo->failure;
die "Ran out of time" if $delay == -1;
sleep $delay;
}
DESCRIPTION
This module is a subclass of Algorithm::Backoff::Exponential that adds
support for adjustable timeouts during each retry. This also comes with
a sane set of defaults as a good baseline for most kinds of retry
operations.
A combination of features solves for most problems that would arise
from retry operations:
* Maximum attempts - Forces the algorithm to give up if repeated
attempts don't yield success.
* Maximum duration - Forces the algorithm to give up if no successes
happen within a certain time frame.
* Exponential backoff - A sqrt(2) exponential delay keeps single
retries from waiting too long, while spreading out repeated retries
that may fail too quickly and run out of max attempts. This also
( run in 0.608 second using v1.01-cache-2.11-cpan-13bb782fe5a )