{"id":22018124,"url":"https://github.com/rvflash/backoff","last_synced_at":"2025-03-23T09:27:34.663Z","repository":{"id":57524081,"uuid":"207107254","full_name":"rvflash/backoff","owner":"rvflash","description":"Fibonacci backoff implementation","archived":false,"fork":false,"pushed_at":"2019-09-14T11:25:38.000Z","size":23,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T16:16:28.071Z","etag":null,"topics":["backoff-strategy","fibonacci-backoff","golang"],"latest_commit_sha":null,"homepage":null,"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/rvflash.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}},"created_at":"2019-09-08T12:10:56.000Z","updated_at":"2022-07-05T07:46:48.000Z","dependencies_parsed_at":"2022-09-26T18:10:55.331Z","dependency_job_id":null,"html_url":"https://github.com/rvflash/backoff","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fbackoff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fbackoff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fbackoff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rvflash%2Fbackoff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rvflash","download_url":"https://codeload.github.com/rvflash/backoff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245081269,"owners_count":20557809,"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-strategy","fibonacci-backoff","golang"],"created_at":"2024-11-30T05:10:00.618Z","updated_at":"2025-03-23T09:27:34.643Z","avatar_url":"https://github.com/rvflash.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fibonacci backoff implementation\n\n[![GoDoc](https://godoc.org/github.com/rvflash/backoff?status.svg)](https://godoc.org/github.com/rvflash/backoff)\n[![Build Status](https://img.shields.io/travis/rvflash/backoff.svg)](https://travis-ci.org/rvflash/backoff)\n[![Code Coverage](https://img.shields.io/codecov/c/github/rvflash/backoff.svg)](http://codecov.io/github/rvflash/backoff?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rvflash/backoff)](https://goreportcard.com/report/github.com/rvflash/backoff)\n\nThe package `backoff` implements a Fibonacci backoff algorithm.\n\n\n### Installation\n    \nTo install it, you need to install Go and set your Go workspace first.\nThen, download and install it:\n\n```bash\n$ go get -u github.com/rvflash/backoff\n```    \nImport it in your code:\n    \n```go\nimport \"github.com/rvflash/backoff\"\n```\n\n### Prerequisite\n\n`backoff` uses the Go modules that required Go 1.11 or later.\nThe `go.mod` file refers to Go 1.13 because the tests uses the new error method `As`.\n\n\n## Features\n\nBased on the Fibonacci suite (1, 1, 2, 3, 5, 8, 13, 21, etc.), the `backoff` strategy do or retry a given task.\nBy default, `DefaultInterval` is used as interval, so the sleep duration is the `current Fibonacci value * 500 * time.Millisecond`.\nWith the `New` method, you can create your own Backoff strategy but by default, the following implementation are available:  \nSee the documentation for more details and samples.\n\n\n### Do \n\n`Do` guarantees to execute at least once the task if the context is not already cancelled.\nAs long as the task return in success and the context not done, BackOff will continue to call it, with a sleep duration based the Fibonacci suite and the BackOff's interval.\n\n* `DoN`: does the same job as Do but limits the number of attempt.\n* `DoUntil`: does the same job as Do but limits the execution to the given deadline.\n\n\n### Retry \n\n`Retry` retries the task until it does not return error or BackOff stops.\n\n* `RetryN`: does the same job as Do but limits the number of attempt.\n* `RetryUntil`: does the same job as Do but limits the execution to the given deadline.\n\n\n## Quick start\n\nAssuming the following code that retry 3 times to run the task if it returns in error.\n\n```go\n\nimport (\n\t\"context\"\n\t\"log\"\n\n\t\"github.com/rvflash/backoff\"\n)\n\nfunc main() {\n\t// task implements the backoff.Func interface.\n\ttask := func(ctx context.Context) error {\n\t\tselect {\n\t\tcase \u003c-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\t\treturn nil\n\t}\n\tn, err := backoff.RetryN(context.Background(), 3, task)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tlog.Printf(\"Nice boy: %d retry, first try in success\", n)\n\t// Output: Nice boy: 0 retry, first try in success\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvflash%2Fbackoff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frvflash%2Fbackoff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frvflash%2Fbackoff/lists"}