{"id":15527245,"url":"https://github.com/restaurant-cheetah/take2","last_synced_at":"2025-04-23T12:23:07.052Z","repository":{"id":59157212,"uuid":"148481497","full_name":"restaurant-cheetah/take2","owner":"restaurant-cheetah","description":"Easily define Take2 🎬 to retry API calls, methods, or just a block of code.","archived":false,"fork":false,"pushed_at":"2020-08-14T17:00:08.000Z","size":64,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-22T01:22:42.499Z","etag":null,"topics":["error-recovery","retry","retry-pattern","retrying","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/restaurant-cheetah.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-09-12T13:04:47.000Z","updated_at":"2025-01-26T09:00:11.000Z","dependencies_parsed_at":"2022-09-13T17:50:55.929Z","dependency_job_id":null,"html_url":"https://github.com/restaurant-cheetah/take2","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/restaurant-cheetah%2Ftake2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restaurant-cheetah%2Ftake2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restaurant-cheetah%2Ftake2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restaurant-cheetah%2Ftake2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/restaurant-cheetah","download_url":"https://codeload.github.com/restaurant-cheetah/take2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250431417,"owners_count":21429470,"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":["error-recovery","retry","retry-pattern","retrying","ruby","ruby-on-rails"],"created_at":"2024-10-02T11:05:11.068Z","updated_at":"2025-04-23T12:23:07.029Z","avatar_url":"https://github.com/restaurant-cheetah.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Take2\n[![CircleCI](https://circleci.com/gh/restaurant-cheetah/take2/tree/master.svg?style=shield)](https://circleci.com/gh/restaurant-cheetah/take2/tree/master)\n![Gem](https://img.shields.io/gem/dt/take2.svg)\n![GitHub last commit](https://img.shields.io/github/last-commit/restaurant-cheetah/take2.svg)\n![Gem](https://img.shields.io/gem/v/take2.svg)  \n1. Define rules for retrying behavior.  \n2. Yield block of code into the with_retry method.  \n3. Things getting take two :)\n\n## Install\n\n```ruby\ngem install take2\n```\n## Examples\n\n```ruby\nclass Service\n  include Take2\n\n  number_of_retries 3\n\n  # Could be configured globally or on class level.\n  retriable_errors Net::HTTPRetriableError, Errno::ECONNRESET\n\n  # Retry unless the response status is 5xx. The implementation is dependent of the http lib in use.\n  retriable_condition proc { |error| error.response.code \u003c 500 }\n\n  # Defines callable code to run before next retry. Could be an out put to some logger.\n  on_retry proc { |error, tries| puts \"#{name} - Retrying.. #{tries} of #{retriable_configuration[:retries]} (#{error})\" }\n\n  # The available strategies are:\n  # type :constant, start: 2 =\u003e [2, 2, 2, 2 ... ]\n  # type :linear, start: 3, factor: 2 =\u003e [3, 6, 12, 24 ... ]\n  # type :fibonacci, start: 2 =\u003e [2, 3, 5, 8, 13 ... ]\n  # type :exponential, start: 3 =\u003e [3, 7, 12, 28, 47 ... ]\n  backoff_strategy type: :fibonacci, start: 3\n\n  class \u003c\u003c self\n    def call\n      with_retry do\n        # Some logic that might raise..\n        # If it will raise retriable, magic happens.\n        # If not the original error re raised\n\n        raise Net::HTTPRetriableError.new('Release the Kraken...many times!!', nil)\n      end\n    end\n\n    # Pass custom options per method call\n    # The class defaults will not be overwritten\n    def read(file)\n      with_retry(retries: 2, retriable: [IOError], retry_proc: proc {}, retry_condition_proc: proc {}) do\n        # Some logic that might raise..\n      end\n    end\n  end\nend  \n\nService.call\n#=\u003e KratosService - Retrying.. 3 of 3 (Release the Kraken...many times!!)\n#=\u003e KratosService - Retrying.. 2 of 3 (Release the Kraken...many times!!)\n#=\u003e KratosService - Retrying.. 1 of 3 (Release the Kraken...many times!!)\n# After the retrying is done, original error re-raised  \n#=\u003e Net::HTTPRetriableError: Release the Kraken...many times!!\n\n# Current configuration hash\nService.retriable_configuration\n\n```\n\n## Configurations\n#### could be implemented as rails initializer\n\n```ruby\n# config/initializers/take2.rb\n\nTake2.configure do |config|\n  config.retries    = 3\n  config.retriable  = [\n      Net::HTTPRetriableError,      \n      Errno::ECONNRESET,\n      IOError\n  ].freeze\n  config.retry_condition_proc = proc { false }\n  config.retry_proc           = proc { Rails.logger.info \"Retry message\" }\n  config.backoff_intervals    = Take2::Backoff.new(:linear, 1).intervals\nend\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestaurant-cheetah%2Ftake2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frestaurant-cheetah%2Ftake2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestaurant-cheetah%2Ftake2/lists"}