Algorithm-Backoff-RetryTimeouts

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

      How much of the remaining time to use for the next attempt's timeout,
      as a factor between 0 and 1.

      In order to prevent a single attempt from using up all of the
      remaining time, an adjustable timeout will force the attempt to only
      use a portion of the time. By default, only 50% of the remaining time
      will be set as the next timeout value.

      * min_adjust_timeout => ufloat (default: 5)

      Minimum timeout value, in seconds.

      This value bypasses any max_actual_duration checks, so the total time
      spent on sleeping and attempts may end up exceeding that value by a
      small amount (up to max_actual_duration + min_adjust_timeout). In
      this case, future failures will return a delay of -1 as expected.

      * timeout_jitter_factor => float (default: 0.1)

      How much randomness to add to the adjustable timeout.

README  view on Meta::CPAN


    Log a failed attempt. If not specified, $timestamp defaults to current
    time. Unlike the base class, this method will return a list containing
    both the suggested delay and the suggested timeout for the next
    attempt.

 delay

        my $delay = $retry_algo->delay;

    Returns the last suggested delay, in seconds.

    The delay will return -1 to suggest that the process should give up and
    fail, if max_attempts or max_actual_duration have been reached.

 timeout

        my $timeout = $retry_algo->delay;

    Returns the last suggested timeout, in seconds. If no attempts have
    been logged, it will suggest an initial timeout to start with.

    This will be a floating-point number, so you may need to convert it to
    an integer if your timeout system doesn't support decimals.

    A timeout of -1 will be returned if max_actual_duration was forcefully
    turned off.

SEE ALSO

lib/Algorithm/Backoff/RetryTimeouts.pm  view on Meta::CPAN

    # No need to require what already has a default
    $args->{initial_delay}{req} = 0;

    # New arguments
    $args->{adjust_timeout_factor} = {
        summary => 'How much of the time left to use in the adjustable timeout',
        schema  => ['ufloat*', between=>[0, 1]],
        default => 0.5,
    };
    $args->{min_adjust_timeout} = {
        summary => 'Minimum adjustable timeout, in seconds',
        schema  => 'ufloat*',
        default => 5,
    };
    $args->{timeout_jitter_factor} = {
        summary => 'How much randomness to add to the adjustable timeout',
        schema  => ['float*', between=>[0, 0.5]],
        default => 0.1,
    };
}

lib/Algorithm/Backoff/RetryTimeouts.pm  view on Meta::CPAN

#pod
#pod How much of the remaining time to use for the next attempt's timeout, as a
#pod factor between 0 and 1.
#pod
#pod In order to prevent a single attempt from using up all of the remaining time, an
#pod adjustable timeout will force the attempt to only use a portion of the time.  By default,
#pod only 50% of the remaining time will be set as the next timeout value.
#pod
#pod =item * min_adjust_timeout => I<ufloat> (default: 5)
#pod
#pod Minimum timeout value, in seconds.
#pod
#pod This value bypasses any C<max_actual_duration> checks, so the total time spent on
#pod sleeping and attempts may end up exceeding that value by a small amount (up to
#pod C<max_actual_duration + min_adjust_timeout>).  In this case, future failures will return
#pod a delay of C<-1> as expected.
#pod
#pod =item * timeout_jitter_factor => I<float> (default: 0.1)
#pod
#pod How much randomness to add to the adjustable timeout.
#pod

lib/Algorithm/Backoff/RetryTimeouts.pm  view on Meta::CPAN

        $self->{_last_timestamp} = $timestamp;
    }

    return ($delay, $timeout);
}

#pod =head2 delay
#pod
#pod     my $delay = $retry_algo->delay;
#pod
#pod Returns the last suggested delay, in seconds.
#pod
#pod The delay will return C<-1> to suggest that the process should give up and fail, if
#pod C<max_attempts> or C<max_actual_duration> have been reached.
#pod
#pod =cut

sub delay {
    my $self = shift;
    return $self->{_prev_delay} // 0;
}

#pod =head2 timeout
#pod
#pod     my $timeout = $retry_algo->delay;
#pod
#pod Returns the last suggested timeout, in seconds.  If no attempts have been logged,
#pod it will suggest an initial timeout to start with.
#pod
#pod This will be a floating-point number, so you may need to convert it to an integer if your
#pod timeout system doesn't support decimals.
#pod
#pod A timeout of C<-1> will be returned if C<max_actual_duration> was forcefully turned off.
#pod
#pod =cut

sub timeout {

lib/Algorithm/Backoff/RetryTimeouts.pm  view on Meta::CPAN


How much of the remaining time to use for the next attempt's timeout, as a
factor between 0 and 1.

In order to prevent a single attempt from using up all of the remaining time, an
adjustable timeout will force the attempt to only use a portion of the time.  By default,
only 50% of the remaining time will be set as the next timeout value.

=item * min_adjust_timeout => I<ufloat> (default: 5)

Minimum timeout value, in seconds.

This value bypasses any C<max_actual_duration> checks, so the total time spent on
sleeping and attempts may end up exceeding that value by a small amount (up to
C<max_actual_duration + min_adjust_timeout>).  In this case, future failures will return
a delay of C<-1> as expected.

=item * timeout_jitter_factor => I<float> (default: 0.1)

How much randomness to add to the adjustable timeout.

lib/Algorithm/Backoff/RetryTimeouts.pm  view on Meta::CPAN


Log a failed attempt.  If not specified, C<$timestamp> defaults to current time.
Unlike the L<base class|Algorithm::Backoff>, this method will return a list containing
both the L<suggested delay|/delay> and the L<suggested timeout|/timeout> for the next
attempt.

=head2 delay

    my $delay = $retry_algo->delay;

Returns the last suggested delay, in seconds.

The delay will return C<-1> to suggest that the process should give up and fail, if
C<max_attempts> or C<max_actual_duration> have been reached.

=head2 timeout

    my $timeout = $retry_algo->delay;

Returns the last suggested timeout, in seconds.  If no attempts have been logged,
it will suggest an initial timeout to start with.

This will be a floating-point number, so you may need to convert it to an integer if your
timeout system doesn't support decimals.

A timeout of C<-1> will be returned if C<max_actual_duration> was forcefully turned off.

=head1 SEE ALSO

L<Algorithm::Backoff> - Base distro for this module

t/00-report-prereqs.t  view on Meta::CPAN

}
else {
    $cpan_meta_error = $@;    # capture error from CPAN::Meta->load_file($source)
    $source = 'static metadata';
}

my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;

# Add static includes into a fake section
for my $mod (@include) {
    $req_hash->{other}{modules}{$mod} = 0;
}

for my $phase ( qw(configure build test runtime develop other) ) {
    next unless $req_hash->{$phase};
    next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});

    for my $type ( qw(requires recommends suggests conflicts modules) ) {
        next unless $req_hash->{$phase}{$type};

t/basic.t  view on Meta::CPAN

    $rt = Algorithm::Backoff::RetryTimeouts->new(
        # for the unit tests
        _start_timestamp      => 0,
        jitter_factor         => 0,
        timeout_jitter_factor => 0,
    );

    $time = 0;
    is($rt->timeout, 25, 'Initial timeout: 25');

    # 1: one second attempt
    test_attempt(
        attempt_time   => 1,
        expected_delay => $sqrt2 - 1,  # sqrt(2)^1 - 1
    );

    # 2: instant failure
    test_attempt(
        attempt_time   => 0,
        expected_delay => 2,  # sqrt(2)^2
    );

    # 3: full timeout
    test_attempt(
        attempt_time   => $rt->timeout,
        expected_delay => 0,
    );

    # 4: one second attempt
    test_attempt(
        attempt_time   => 1,
        expected_delay => 3,  # sqrt(2)^4 - 1
    );

    # 5: full timeout (with min_adjust_timeout trigger)
    test_attempt(
        expected_delay   => 0,
        expected_timeout => 5,
    );

t/basic.t  view on Meta::CPAN


        # for the unit tests
        _start_timestamp      => 0,
        jitter_factor         => 0,
        timeout_jitter_factor => 0,
    );

    $time = 0;
    is($rt->timeout, 12.5, 'Initial timeout: 12.5');

    # 1: one second attempt
    test_attempt(
        attempt_time   => 1,
        expected_delay => $sqrt2 - 1,  # sqrt(2)^1 - 1
    );

    # 2: instant failure
    test_attempt(
        attempt_time   => 0,
        expected_delay => 2,  # sqrt(2)^2
    );

    # 3: full timeout
    test_attempt(
        expected_delay => 0,
    );

    # 4: one second attempt
    test_attempt(
        attempt_time   => 1,
        expected_delay => 3,  # sqrt(2)^4 - 1
    );

    # 5: full timeout
    test_attempt(
        expected_delay => 0,
    );



( run in 0.842 second using v1.01-cache-2.11-cpan-39bf76dae61 )