Algorithm-Backoff-RetryTimeouts
view release on metacpan or search on metacpan
lib/Algorithm/Backoff/RetryTimeouts.pm view on Meta::CPAN
#pod Unlike the L<base class|Algorithm::Backoff>, this method will return a list containing
#pod both the L<suggested delay|/delay> and the L<suggested timeout|/timeout> for the next
#pod attempt.
#pod
#pod =cut
sub failure {
my ($self, $timestamp) = @_;
$timestamp //= time;
my ($delay, $timeout) = $self->SUPER::failure($timestamp);
# Fix certain values if the check failed max duration/attempts checks
$timeout //= $self->timeout;
if ($delay == -1) {
$self->{_attempts}++;
$self->{_last_timestamp} = $timestamp;
}
return ($delay, $timeout);
}
lib/Algorithm/Backoff/RetryTimeouts.pm view on Meta::CPAN
my $max = $timeout * (1 + $jitter);
return $min + ($max - $min) * rand();
}
sub _consider_actual_delay {
my $self = shift;
# See https://github.com/perlancar/perl-Algorithm-Backoff/issues/1
$self->{_last_delay} = $self->{_prev_delay} //= 0;
return $self->SUPER::_consider_actual_delay(@_);
}
sub _success_or_failure {
my ($self, $is_success, $timestamp) = @_;
# If this is the first time, the _last_timestamp should be set to the start, not
# $timestamp. This will prevent issues with the first attempt causing unnecessary
# delays (ie: waiting 1.4s after the first attempt took longer than that).
$self->{_last_timestamp} //= $self->{_start_timestamp};
my $delay = $self->SUPER::_success_or_failure($is_success, $timestamp);
return $self->_set_last_timeout($delay, $timestamp);
}
#pod =head1 SEE ALSO
#pod
#pod L<Algorithm::Backoff> - Base distro for this module
#pod
#pod =cut
1;
( run in 0.996 second using v1.01-cache-2.11-cpan-49f99fa48dc )