{"id":13582142,"url":"https://github.com/Rican7/retry","last_synced_at":"2025-04-06T13:32:55.899Z","repository":{"id":46108911,"uuid":"62120017","full_name":"Rican7/retry","owner":"Rican7","description":"A simple, stateless, functional mechanism to perform actions repetitively until successful.","archived":false,"fork":false,"pushed_at":"2023-02-14T20:49:40.000Z","size":56,"stargazers_count":474,"open_issues_count":3,"forks_count":28,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-05T06:00:59.744Z","etag":null,"topics":["backoff","delay","exponential","fibonacci","functional","go","incremental","jitter","limit","linear","retry","stateless","wait"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/Rican7/retry","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/Rican7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2016-06-28T07:34:15.000Z","updated_at":"2024-10-03T15:41:02.000Z","dependencies_parsed_at":"2024-06-18T12:37:26.373Z","dependency_job_id":null,"html_url":"https://github.com/Rican7/retry","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rican7%2Fretry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rican7%2Fretry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rican7%2Fretry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rican7%2Fretry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rican7","download_url":"https://codeload.github.com/Rican7/retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223253723,"owners_count":17114242,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["backoff","delay","exponential","fibonacci","functional","go","incremental","jitter","limit","linear","retry","stateless","wait"],"created_at":"2024-08-01T15:02:27.089Z","updated_at":"2024-11-05T22:30:22.198Z","avatar_url":"https://github.com/Rican7.png","language":"Go","readme":"# retry\n\n[![Build Status](https://github.com/Rican7/retry/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/Rican7/retry/actions/workflows/main.yml)\n[![Coverage Status](https://coveralls.io/repos/github/Rican7/retry/badge.svg)](https://coveralls.io/github/Rican7/retry)\n[![Go Report Card](https://goreportcard.com/badge/Rican7/retry)](http://goreportcard.com/report/Rican7/retry)\n[![Go Reference](https://pkg.go.dev/badge/github.com/Rican7/retry.svg)](https://pkg.go.dev/github.com/Rican7/retry)\n[![Latest Stable Version](https://img.shields.io/github/release/Rican7/retry.svg?style=flat)](https://github.com/Rican7/retry/releases)\n\nA simple, stateless, functional mechanism to perform actions repetitively until successful.\n\n\n## Project Status\n\nThis project is currently in \"pre-release\". While the code is heavily tested, the API may change.\nUse a tagged version or vendor this dependency if you plan on using it.\n\nThat said, this code has been used in production without issue for years, and has been used by some relatively\n[high-profile projects/codebases](https://pkg.go.dev/github.com/Rican7/retry?tab=importedby).\n\n\n## Examples\n\n### Basic\n\n```go\nretry.Retry(func(attempt uint) error {\n\treturn nil // Do something that may or may not cause an error\n})\n```\n\n### File Open\n\n```go\nconst logFilePath = \"/var/log/myapp.log\"\n\nvar logFile *os.File\n\nerr := retry.Retry(func(attempt uint) error {\n\tvar err error\n\n\tlogFile, err = os.Open(logFilePath)\n\n\treturn err\n})\n\nif err != nil {\n\tlog.Fatalf(\"Unable to open file %q with error %q\", logFilePath, err)\n}\n\nlogFile.Chdir() // Do something with the file\n```\n\n### HTTP request with strategies and backoff\n\n```go\nvar response *http.Response\n\naction := func(attempt uint) error {\n\tvar err error\n\n\tresponse, err = http.Get(\"https://api.github.com/repos/Rican7/retry\")\n\n\tif err == nil \u0026\u0026 response != nil \u0026\u0026 response.StatusCode \u003e 200 {\n\t\terr = fmt.Errorf(\"failed to fetch (attempt #%d) with status code: %d\", attempt, response.StatusCode)\n\t}\n\n\treturn err\n}\n\nerr := retry.Retry(\n\taction,\n\tstrategy.Limit(5),\n\tstrategy.Backoff(backoff.Fibonacci(10*time.Millisecond)),\n)\n\nif err != nil {\n\tlog.Fatalf(\"Failed to fetch repository with error %q\", err)\n}\n```\n\n### Retry with backoff jitter\n\n```go\naction := func(attempt uint) error {\n\treturn errors.New(\"something happened\")\n}\n\nseed := time.Now().UnixNano()\nrandom := rand.New(rand.NewSource(seed))\n\nretry.Retry(\n\taction,\n\tstrategy.Limit(5),\n\tstrategy.BackoffWithJitter(\n\t\tbackoff.BinaryExponential(10*time.Millisecond),\n\t\tjitter.Deviation(random, 0.5),\n\t),\n)\n```\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRican7%2Fretry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRican7%2Fretry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRican7%2Fretry/lists"}