- SEE ALSO
- COPYRIGHT AND LICENSE
retry-exponential - Retry a command with exponential backoff
This document describes version 0.003 of retry-exponential (from Perl distribution App-AlgorithmBackoffUtils), released on 2019-06-08.
% retry-exponential [options] <command>
* marks required options.
Can be specified multiple times.
Number of seconds to wait after a success.
Initial delay for the first attempt after failure, in seconds.
Comma-separated list of exit codes that should trigger retry.
By default, all non-zero exit codes will trigger retry.
- --skip-delay, -D
Do not delay at all.
Useful for testing, along with --dry-run, when you just want to see how the retries are done (the number of retries, along with the number of seconds of delays) by seeing the log messages, without actually delaying.
Comma-separated list of exit codes that mean success.
By default, only exit code 0 means success.
Whether to consider actual delay.
If set to true, will take into account the actual delay (timestamp difference). For example, when using the Constant strategy of delay=2, you log failure() again right after the previous failure() (i.e. specify the same timestamp). failure() will then return ~2+2 = 4 seconds. On the other hand, if you waited 2 seconds before calling failure() again (i.e. specify the timestamp that is 2 seconds larger than the previous timestamp), failure() will return 2 seconds. And if you waited 4 seconds or more, failure() will return 0.
How much to add randomness.
If you set this to a value larger than 0, the actual delay will be between a random number between original_delay * (1-jitter_factor) and original_delay * (1+jitter_factor). Jitters are usually added to avoid so-called "thundering herd" problem.
The jitter will be applied to delay on failure as well as on success.
Maximum number of seconds for all of the attempts (0 means unlimited).
If set to a positive number, will limit the number of seconds for all of the attempts. This setting is used to limit the amount of time you are willing to spend on a task. For example, when using the Exponential strategy of initial_delay=3 and max_attempts=10, the delays will be 3, 6, 12, 24, ... If failures are logged according to the suggested delays, and max_actual_duration is set to 21 seconds, then the third failure() will return -1 instead of 24 because 3+6+12 >= 21, even though max_attempts has not been exceeded.
Maximum number consecutive failures before giving up.
0 means to retry endlessly without ever giving up. 1 means to give up after a single failure (i.e. no retry attempts). 2 means to retry once after a failure. Note that after a success, the number of attempts is reset (as expected). So if max_attempts is 3, and if you fail twice then succeed, then on the next failure the algorithm will retry again for a maximum of 3 times.
Maximum delay time, in seconds.
Maximum delay time, in seconds.
Shortcut for --log-level=debug.
Set log level.
Shortcut for --log-level=error.
Shortcut for --log-level=trace.
Shortcut for --log-level=info.
Choose output format, e.g. json, text.
Set output format to json.
When outputing as JSON, strip result envelope.
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:
Run in simulation mode (also via DRY_RUN=1).
- --help, -h, -?
Display help message and exit.
- --version, -v
Display program's version and exit.
This script has shell tab completion capability with support for several shells.
To activate bash completion for this script, put:
complete -C retry-exponential retry-exponential
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
To activate tcsh completion for this script, put:
complete retry-exponential 'p/*/`retry-exponential`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
For fish and zsh, install shcompgen as described above.
Please visit the project's homepage at https://metacpan.org/release/App-AlgorithmBackoffUtils.
Source repository is at https://github.com/perlancar/perl-App-AlgorithmBackoffUtils.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-AlgorithmBackoffUtils
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
This software is copyright (c) 2019 by email@example.com.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.