{"id":17645585,"url":"https://github.com/sgaunet/retry","last_synced_at":"2026-04-15T23:33:28.473Z","repository":{"id":206862545,"uuid":"716757869","full_name":"sgaunet/retry","owner":"sgaunet","description":"simple and flexible command-line tool that retries a given command until it succeeds or a maximum number of attempts is reached. Ideal for automating workflows, handling flaky commands in CI/CD pipelines, and improving reliability in development and testing environments.","archived":false,"fork":false,"pushed_at":"2026-03-31T19:22:49.000Z","size":894,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-31T21:28:31.523Z","etag":null,"topics":["automation","binary","ci","cli","command-line","devops","flaky-tests","golang","linux","retry","task-runner","testing","utility"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgaunet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["sgaunet"]}},"created_at":"2023-11-09T20:10:22.000Z","updated_at":"2026-03-31T19:22:46.000Z","dependencies_parsed_at":"2023-11-12T21:28:10.654Z","dependency_job_id":"c7d8dfd3-0109-4dc2-acf7-2ead9652bdb7","html_url":"https://github.com/sgaunet/retry","commit_stats":null,"previous_names":["sgaunet/retry"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/sgaunet/retry","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgaunet%2Fretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgaunet%2Fretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgaunet%2Fretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgaunet%2Fretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgaunet","download_url":"https://codeload.github.com/sgaunet/retry/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgaunet%2Fretry/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31865068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","binary","ci","cli","command-line","devops","flaky-tests","golang","linux","retry","task-runner","testing","utility"],"created_at":"2024-10-23T10:57:39.097Z","updated_at":"2026-04-15T23:33:28.468Z","avatar_url":"https://github.com/sgaunet.png","language":"Go","funding_links":["https://github.com/sponsors/sgaunet"],"categories":[],"sub_categories":[],"readme":"[![Go Report Card](https://goreportcard.com/badge/github.com/sgaunet/retry)](https://goreportcard.com/report/github.com/sgaunet/retry)\n![GitHub Downloads](https://img.shields.io/github/downloads/sgaunet/retry/total)\n![GitHub Release](https://img.shields.io/github/v/release/sgaunet/retry)\n![Test Coverage](https://raw.githubusercontent.com/wiki/sgaunet/retry/coverage-badge.svg)\n[![Linter](https://github.com/sgaunet/retry/actions/workflows/linter.yml/badge.svg)](https://github.com/sgaunet/retry/actions/workflows/linter.yml)\n[![Vulnerability Scan](https://github.com/sgaunet/retry/actions/workflows/vulnerability-scan.yml/badge.svg)](https://github.com/sgaunet/retry/actions/workflows/vulnerability-scan.yml)\n[![Generate coverage badges](https://github.com/sgaunet/retry/actions/workflows/coverage.yml/badge.svg)](https://github.com/sgaunet/retry/actions/workflows/coverage.yml)\n[![Snapshot](https://github.com/sgaunet/retry/actions/workflows/snapshot.yml/badge.svg)](https://github.com/sgaunet/retry/actions/workflows/snapshot.yml)\n[![Release](https://github.com/sgaunet/retry/actions/workflows/release.yml/badge.svg)](https://github.com/sgaunet/retry/actions/workflows/release.yml)\n\n# retry\n\nretry command will execute X times a failed command until it's successful. Supports both fixed delays and exponential backoff strategies. Useful for flaky tests, waiting for services to become available, or handling transient failures.\n\n## Features\n\n- **Fixed delay**: Traditional constant delay between retries\n- **Exponential backoff**: Smart retry strategy that increases delays exponentially\n- **Configurable**: Customize retry count, delays, multipliers, and maximum delays\n- **Backward compatible**: Existing scripts continue to work unchanged\n- **Environment variables**: Configure via environment variables\n\n# Getting started\n\n## Basic Usage\n\n```bash\n# Basic retry with default settings (3 attempts, fixed delay)\nretry \"flaky-command\"\n\n# Custom retry count and fixed delay\nretry --max-tries 5 --delay 2s \"curl https://api.example.com\"\n\n# Exponential backoff (recommended for network operations)\nretry --backoff exponential --base-delay 1s --max-delay 30s \"curl https://api.example.com\"\n```\n\n## Exponential Backoff Examples\n\n```bash\n# Basic exponential backoff (1s, 2s, 4s, 8s, ...)\nretry --backoff exponential \"make test\"\n\n# Custom exponential backoff with shorter delays  \nretry --backoff exp --base-delay 100ms --multiplier 1.5 --max-delay 10s \"flaky-service-check\"\n\n# Short form flags\nretry -B exp -b 500ms -M 1m -t 10 \"network-dependent-command\"\n```\n\n## All Available Options\n\n```\n$ ./retry --help\nUsage:\n  retry [flags] \"command\"\n\nFlags:\n  -B, --backoff string      backoff strategy (fixed, exponential) (default \"fixed\")\n  -b, --base-delay string   base delay for exponential backoff (default \"1s\")\n  -d, --delay string        delay between retries (e.g., 1s, 500ms, 2m) (default \"0s\")\n  -h, --help                help for retry\n  -M, --max-delay string    maximum delay for exponential backoff (default \"5m\")\n  -t, --max-tries uint      maximum number of retry attempts (0 for infinite) (default 3)\n      --multiplier float    multiplier for exponential backoff (default 2)\n  -v, --verbose             enable verbose output\n```\n\n## Environment Variables\n\n```bash\nexport RETRY_MAX_TRIES=5\nexport RETRY_BACKOFF=exponential  \nexport RETRY_BASE_DELAY=500ms\nexport RETRY_MAX_DELAY=30s\nretry \"your-command\"\n```\n\n\nDemo:\n\n![demo](doc/demo.gif)\n\n## Using as a Go Library\n\nIn addition to the CLI tool, you can use `retry` as a Go library in your own applications.\n\n### Installation\n\n```bash\ngo get github.com/sgaunet/retry\n```\n\n### Basic Usage\n\n```go\nimport (\n    \"context\"\n    \"time\"\n\n    \"github.com/sgaunet/retry/pkg/logger\"\n    \"github.com/sgaunet/retry/pkg/retry\"\n)\n\nfunc main() {\n    // Create retry with max 5 attempts\n    r, _ := retry.NewRetry(\"your-command\", retry.NewStopOnMaxTries(5))\n\n    // Add exponential backoff\n    r.SetBackoffStrategy(retry.NewExponentialBackoff(\n        time.Second,    // base delay\n        time.Minute,    // max delay\n        2.0,            // multiplier\n    ))\n\n    // Run with context and logger\n    appLogger := logger.NewLogger(\"info\")\n    err := r.RunWithLogger(context.Background(), appLogger)\n    if err != nil {\n        // handle error\n    }\n}\n```\n\n### Composite Conditions\n\nCombine multiple stop conditions with AND/OR logic:\n\n```go\n// Stop after 10 tries OR after 5 minutes\ncondition := retry.NewCompositeCondition(\n    retry.LogicOR,\n    retry.NewStopOnMaxTries(10),\n    retry.NewStopOnTimeout(5 * time.Minute),\n)\nr, _ := retry.NewRetry(\"curl -sf https://api.example.com/health\", condition)\n```\n\n### Success Conditions\n\nDefine custom success criteria beyond just exit code 0:\n\n```go\nr, _ := retry.NewRetry(\"curl https://api.example.com\", retry.NewStopOnMaxTries(10))\n\n// Consider successful if output contains \"healthy\"\nsuccessCond, _ := retry.NewSuccessContains(\"healthy\")\nr.SetSuccessConditions([]retry.ConditionRetryer{successCond})\n```\n\n### Available Backoff Strategies\n\n- **Fixed**: Constant delay between retries\n- **Exponential**: Delay doubles (or multiplies) each attempt\n- **Linear**: Delay increases by a fixed increment\n- **Fibonacci**: Delay follows the Fibonacci sequence\n- **Jitter**: Wraps any strategy with randomness to avoid thundering herd\n- **Custom**: User-defined delay sequence\n\n### API Documentation\n\nFull API documentation is available at: https://pkg.go.dev/github.com/sgaunet/retry/pkg/retry\n\nSee [examples/](examples/) for complete runnable examples.\n\n## Real-World Examples\n\nFor comprehensive CLI usage examples, see the [examples/](examples/) directory:\n\n- **CI/CD Integration**: [GitHub Actions](examples/ci-cd/github-actions.yml), [GitLab CI](examples/ci-cd/gitlab-ci.yml)\n- **Docker \u0026 Containers**: [Health checks](examples/docker/healthcheck.sh), [Dockerfile](examples/docker/Dockerfile.example), [Compose](examples/docker/docker-compose.yml)\n- **Databases**: [Migrations](examples/databases/migration-retry.sh), [Connection waiting](examples/databases/connection-wait.sh)\n- **Networking**: [API health checks](examples/networking/api-endpoint-check.sh), [Downloads](examples/networking/download-with-retry.sh)\n- **Kubernetes**: [Init containers](examples/kubernetes/init-container.yaml), [Jobs](examples/kubernetes/job-with-retry.yaml)\n- **Testing**: [Flaky tests](examples/testing/flaky-tests.sh), [E2E tests](examples/testing/e2e-with-retry.sh)\n- **Services**: [Startup waiting](examples/services/service-startup-wait.sh), [Dependencies](examples/services/dependency-check.sh)\n\n# Install\n\n## From binary \n\nDownload the binary in the release section. \n\n## From Docker image\n\nDocker registry is: ghcr.io/sgaunet/retry\n\nThe docker image is only interesting to copy the binary in your docker image.\n\n# Development\n\nThis project is using :\n\n* golang\n* [task for development](https://taskfile.dev/#/)\n* docker\n* [docker buildx](https://github.com/docker/buildx)\n* docker manifest\n* [goreleaser](https://goreleaser.com/)\n* [pre-commit](https://pre-commit.com/)\n\nThere are hooks executed in the precommit stage. Once the project cloned on your disk, please install pre-commit:\n\n```\nbrew install pre-commit\n```\n\nInstall tools:\n\n```\ntask dev:install-prereq\n```\n\nAnd install the hooks:\n\n```\ntask dev:install-pre-commit\n```\n\nIf you like to launch manually the pre-commmit hook:\n\n```\ntask dev:pre-commit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgaunet%2Fretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgaunet%2Fretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgaunet%2Fretry/lists"}