Async::Timeouts - A library of tools for managing timeouts and retries
use Async::Timeouts;
timeout({...}, :timeout<3>, :retry<exponential>);
... much more to come ...
Async::Timeouts
is designed to be an easy-to-use wrapper around
timing out both synchronous and asynchronous execution of either
code within your program or external programs/interfaces.
Retry
is a class that implements various retry
strategies by providing a pause
method that returns the "next"
time increment to pause before retrying the action. Retry doesn't
actually implement the retry mechanism itself, it just encapsulates
the strategy / algorithm for determining the next pause or end of
retry sequence.
You can instantiate a Retry objet using the exported enums,
RetryMode
and RetryRandom
or by using their string equivalents
like so:
Retry.new(:mode<exponential>, :random<none>)
The parameters are:
:mode
- The backoff mode (enumeration inRetryMode
. Can be any of:immediate
- No pause between retriesconstant
- Pause:basis
time units between retrieslinear
- Increase the pause by:basis
each retryexponential
- Raise:basis
to the number of retriespolynomial
- Raise number of retries to:basis
custom
- Provided:sequence
is usedfibonacci
- Returned pause values are the Fibbonacci sequence
:random
- How/if to randomly modify the backoff (enumeration inRetryRandom
). Can be any of:none
- No randomnessalways
- Returned value will be in the range of 0 to the non-random value.increasing
- Returned value will be randomized, but will be larger than the previous returned value.first
- Only randomize the first returned value.
:max-attempts
- Maximum number of retries, after which thepause
method will return a failure of typeX::RetryLimit
.:max-elapsed
- If a returned pause would increase the total elapsed retry pauses to be greater than this value (if defined) then a failure of typeX::RetryLimit
is returned instead.:basis
- The constant value whose use is:mode
-dependant.:scale
- Scaling factor for returnedpause
values. Defaults to 1.:sequence
-If:mode
iscustom
, then this parameter is required and must contain a sequence or list of pause values.
TBD...
(c) 2019 by Aaron Sherman <ajs@ajs.com>
Artistic License 2.0, see LICENSE for details.