{"id":13807061,"url":"https://github.com/spider-gazelle/simple_retry","last_synced_at":"2025-05-06T21:45:53.314Z","repository":{"id":92225371,"uuid":"253709406","full_name":"spider-gazelle/simple_retry","owner":"spider-gazelle","description":"a tool for retrying code blocks","archived":false,"fork":false,"pushed_at":"2021-05-26T01:48:08.000Z","size":10,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T23:51:34.701Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/spider-gazelle.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}},"created_at":"2020-04-07T06:42:45.000Z","updated_at":"2023-09-22T06:10:38.000Z","dependencies_parsed_at":"2023-06-08T01:30:22.644Z","dependency_job_id":null,"html_url":"https://github.com/spider-gazelle/simple_retry","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fsimple_retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fsimple_retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fsimple_retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spider-gazelle%2Fsimple_retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spider-gazelle","download_url":"https://codeload.github.com/spider-gazelle/simple_retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229559919,"owners_count":18092226,"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":[],"created_at":"2024-08-04T01:01:20.215Z","updated_at":"2024-12-13T15:33:33.220Z","avatar_url":"https://github.com/spider-gazelle.png","language":"Crystal","funding_links":[],"categories":["Misc"],"sub_categories":[],"readme":"# Simple Retry\n\n[![CI](https://github.com/spider-gazelle/simple_retry/actions/workflows/ci.yml/badge.svg)](https://github.com/spider-gazelle/simple_retry/actions/workflows/ci.yml)\n\nA library for managing blocks of code that you might want to retry when an error occurs.\n\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     simple_retry:\n       github: spider-gazelle/simple_retry\n   ```\n\n2. Run `shards install`\n\n\n## Usage\n\n```crystal\nrequire \"simple_retry\"\n\nSimpleRetry.try_to do\n  # Something that should succeed eventually\n  num = rand(10)\n  raise \"bad number #{num}\" if num \u003c 5\n\n  # Return the number\n  num\nend\n```\n\nThere are a number of options you can use to customise\n\n```crystal\nrequire \"simple_retry\"\n\nSimpleRetry.try_to(\n  # Runs the block at most 5 times\n  max_attempts: 5,\n  # Will always stop retrying on these errors\n  raise_on: DivisionByZeroError | ArgumentError,\n  # Will only retry on these errors\n  retry_on: Exception,\n  # Initial delay time after first retry\n  base_interval: 10.milliseconds,\n  # Exponentially increase delay up to this period\n  max_interval: 10.seconds,\n  # Adjust the exponential growth by a random amount\n  randomise: 10.milliseconds\n) do |run_count : UInt64, last_error : Exception?, next_delay_time : Time::Span|\n  # Something that should succeed\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspider-gazelle%2Fsimple_retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspider-gazelle%2Fsimple_retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspider-gazelle%2Fsimple_retry/lists"}