Skip to main content

Retry a command with exponential backoff and jitter.

Project description

recur

This command-line tool runs a single command repeatedly until it succeeds or allowed attempts run out. It implements optional exponential backoff with configurable jitter.

It was inspired by retry-cli. I wanted to have something like it, but as a single-file script without the Node.js dependency. The result depends only on Python and its standard library.

The CLI options are modeled after the parameters of the retry decorator, which Python programmers may know. However, I do not use the retry package or its code. The jitter behavior is different from retry. Jitter is applied starting with the first retry, not the second. I think this is what the user expects. A single-number jitter argument results in random jitter picked uniformly from between zero and that number every time.

Requirements

Python 3.8 or later.

Installation

The recommended way to install recur is from PyPI with pipx.

pipx install recur-command
# or
pip install --user recur-command

Usage

usage: recur [-h] [-V] [-b BACKOFF] [-d DELAY] [-j JITTER] [-m MAX] [-t TRIES]
             [-v]
             command ...

Retry a command with exponential backoff and jitter.

positional arguments:
  command               command to run
  args                  arguments

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -b BACKOFF, --backoff BACKOFF
                        multiplier applied to delay on every attempt (default:
                        1, no backoff)
  -d DELAY, --delay DELAY
                        constant or initial exponential delay (seconds,
                        default: 0)
  -j JITTER, --jitter JITTER
                        additional random delay (maximum seconds or "min,max"
                        seconds, default: "0,0")
  -m MAX, --max-delay MAX
                        maximum delay (seconds, default: 86400)
  -t TRIES, --tries TRIES
                        maximum number of attempts (negative for infinite,
                        default: 3)
  -v, --verbose         announce failures

License

MIT.

Alternatives

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

recur_command-0.1.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

recur_command-0.1.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page