Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

0x logo

0×/retry

Retry any command with exponential backoff. One tool, one job.


License: MIT 0x Suite


Why

Shell retry loops suck. You rewrite them constantly, get the backoff wrong, and forget 2>&1. retry handles it so you don't have to.

# Instead of this:
for i in 1 2 3 4 5; do
  curl https://api.com && break
  sleep $((2**i))
done

# Do this:
retry -t 5 -b exp -- curl https://api.com

Install

curl -sSL https://raw.githubusercontent.com/0xProgress/retry/main/install.sh | sh

This clones the repo, builds it with make, and installs the binary to /usr/local/bin (or $PREFIX if set). Requires git, make, and Go on your PATH to build — the resulting binary itself is a single static executable with zero runtime dependencies.

Prefer to build manually?
git clone https://github.com/0xProgress/retry.git
cd retry
make build
cp retry /usr/local/bin/retry   # or wherever you keep binaries

Or, if you just want it on your $GOPATH/bin:

go install github.com/0xProgress/retry@latest

Usage

# Retry up to 3 times
retry --times 3 -- ping google.com

# Exponential backoff (1s → 2s → 4s → 8s)
retry -t 5 -b exp -- curl -s https://flaky-api.com

# Fixed interval (every 5 seconds)
retry -t 10 -d 5 -- npm publish

# Only retry on specific errors
retry -t 3 --retry-if "Connection refused|timeout" -- ./my-script

Options

Flag Description Default
-t, --times N Max attempts 5
-d, --delay N Base delay in seconds 1
-b, --backoff TYPE linear, exp, or fixed linear
--retry-if RE Only retry if stderr matches regex (all failures)
-v, --verbose Show attempt timing off
--no-color Disable color output auto-detected
--version Print version —
-h, --help Show help —

Exit Codes

Code Meaning
0 Command succeeded
1 Failed after all retries
2 Invalid arguments
3 Command not found
128+N Command was terminated by signal N (e.g. 130 = SIGINT)

Real-world examples

CI pipeline

- name: Deploy
  run: retry -t 3 -b exp -- eb deploy

Database migrations

retry -t 10 --retry-if "deadlock|timeout" -- \
  psql -c "ALTER TABLE users ADD COLUMN email_verified BOOLEAN;"

Flaky tests

retry -t 3 -v -- go test ./pkg/integration/...

Philosophy

Part of the 0× suite — tools that do one job, have zero bloat, and stay out of your way.

  • No config files
  • No runtime dependencies (single static binary once built)
  • No surprises
  • --help is all the docs you need

License

Licensed under MIT

About

Retry any command with exponential backoff

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages