line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Retry::ExponentialBackoff; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-10'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
54799
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
354
|
use parent qw(Algorithm::Retry); |
|
1
|
|
|
|
|
254
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our %SPEC; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$SPEC{new} = { |
14
|
|
|
|
|
|
|
v => 1.1, |
15
|
|
|
|
|
|
|
is_class_meth => 1, |
16
|
|
|
|
|
|
|
is_func => 0, |
17
|
|
|
|
|
|
|
args => { |
18
|
|
|
|
|
|
|
%Algorithm::Retry::attr_consider_actual_delay, |
19
|
|
|
|
|
|
|
%Algorithm::Retry::attr_max_attempts, |
20
|
|
|
|
|
|
|
%Algorithm::Retry::attr_jitter_factor, |
21
|
|
|
|
|
|
|
%Algorithm::Retry::attr_delay_on_success, |
22
|
|
|
|
|
|
|
%Algorithm::Retry::attr_max_delay, |
23
|
|
|
|
|
|
|
initial_delay => { |
24
|
|
|
|
|
|
|
summary => 'Initial delay for the first attempt after failure, '. |
25
|
|
|
|
|
|
|
'in seconds', |
26
|
|
|
|
|
|
|
schema => 'ufloat*', |
27
|
|
|
|
|
|
|
req => 1, |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
exponent_base => { |
30
|
|
|
|
|
|
|
schema => 'ufloat*', |
31
|
|
|
|
|
|
|
default => 2, |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
result_naked => 1, |
35
|
|
|
|
|
|
|
result => { |
36
|
|
|
|
|
|
|
schema => 'obj*', |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _success { |
41
|
1
|
|
|
1
|
|
3
|
my ($self, $timestamp) = @_; |
42
|
1
|
|
|
|
|
4
|
$self->{delay_on_success}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _failure { |
46
|
9
|
|
|
9
|
|
15
|
my ($self, $timestamp) = @_; |
47
|
|
|
|
|
|
|
my $delay = $self->{initial_delay} * |
48
|
9
|
|
|
|
|
108
|
$self->{exponent_base} ** ($self->{_attempts}-1); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
# ABSTRACT: Backoff exponentially |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |