line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Retry::ExponentialBackoff; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2019-04-08'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
67707
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
437
|
use parent qw(Algorithm::Retry); |
|
1
|
|
|
|
|
302
|
|
|
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_max_attempts, |
19
|
|
|
|
|
|
|
%Algorithm::Retry::attr_jitter_factor, |
20
|
|
|
|
|
|
|
%Algorithm::Retry::attr_delay_on_success, |
21
|
|
|
|
|
|
|
%Algorithm::Retry::attr_max_delay, |
22
|
|
|
|
|
|
|
initial_delay => { |
23
|
|
|
|
|
|
|
summary => 'Initial delay for the first attempt after failure, '. |
24
|
|
|
|
|
|
|
'in seconds', |
25
|
|
|
|
|
|
|
schema => 'ufloat*', |
26
|
|
|
|
|
|
|
req => 1, |
27
|
|
|
|
|
|
|
}, |
28
|
|
|
|
|
|
|
exponent_base => { |
29
|
|
|
|
|
|
|
schema => 'ufloat*', |
30
|
|
|
|
|
|
|
default => 2, |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
result_naked => 1, |
34
|
|
|
|
|
|
|
result => { |
35
|
|
|
|
|
|
|
schema => 'obj*', |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _success { |
40
|
1
|
|
|
1
|
|
4
|
my ($self, $timestamp) = @_; |
41
|
1
|
|
|
|
|
3
|
$self->{delay_on_success}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _failure { |
45
|
9
|
|
|
9
|
|
21
|
my ($self, $timestamp) = @_; |
46
|
|
|
|
|
|
|
my $delay = $self->{initial_delay} * |
47
|
9
|
|
|
|
|
35
|
$self->{exponent_base} ** ($self->{_attempts}-1); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
# ABSTRACT: Backoff exponentially |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |