{"id":15288743,"url":"https://github.com/simplybuilt/activejob-retriable","last_synced_at":"2025-11-11T18:31:38.563Z","repository":{"id":34874622,"uuid":"38883562","full_name":"SimplyBuilt/activejob-retriable","owner":"SimplyBuilt","description":"🔁 Automatically retry failed ActiveJobs","archived":false,"fork":false,"pushed_at":"2017-04-25T15:53:49.000Z","size":63,"stargazers_count":50,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-14T19:40:34.515Z","etag":null,"topics":["activejob","backend","rails","sidekiq"],"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/SimplyBuilt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-10T14:11:34.000Z","updated_at":"2024-10-04T13:23:00.000Z","dependencies_parsed_at":"2022-06-27T12:03:16.058Z","dependency_job_id":null,"html_url":"https://github.com/SimplyBuilt/activejob-retriable","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/SimplyBuilt%2Factivejob-retriable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplyBuilt%2Factivejob-retriable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplyBuilt%2Factivejob-retriable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimplyBuilt%2Factivejob-retriable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimplyBuilt","download_url":"https://codeload.github.com/SimplyBuilt/activejob-retriable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219846842,"owners_count":16556424,"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":["activejob","backend","rails","sidekiq"],"created_at":"2024-09-30T15:53:01.680Z","updated_at":"2025-11-11T18:31:38.508Z","avatar_url":"https://github.com/SimplyBuilt.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"ActiveJob::Retriable\n====================\n\n[![Build Status](https://travis-ci.org/SimplyBuilt/activejob-retriable.svg)](https://travis-ci.org/SimplyBuilt/activejob-retriable)\n[![Gem Version](https://badge.fury.io/rb/activejob-retriable.svg)](https://rubygems.org/gems/activejob-retriable)\n[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n\nAutomatically retry failed ActiveJobs with an exponential back-off.\n\nThis gem aims to mimic most of the functionality of Sidekiq's `RetryJobs` middleware but operates on\nthe ActiveJob layer.\n\n## Installation\n\nTo install the gem, add the following to your Gemfile:\n\n```ruby\ngem \"activejob-retriable\"\n```\n\nIf you're using Rails 5, use the branch master off Github for support.\nOnce the first stable release of Rails 5 is out we will push a 5.0\nversion of gem.\n\n```ruby\ngem \"activejob-retriable\", github: \"SimplyBuilt/activejob-retriable\"\n```\n\n## Usage\n\nThe simplest way to use this gem is to include the following your\n`ApplicationJob` class\n\n```ruby\nclass ApplicationJob \u003c ActiveJob::Base\n  include ActiveJob::Retriable\nend\n```\n\nA `max_retry` class method as well as before, after and around exception callbacks\nwill now be available to all your Jobs. For example:\n\n```ruby\nclass MyJob \u003c ApplicationJob\n  max_retry 12\n\n  after_exception do\n    # Record exeception to our fictitious error service\n    ErrorNotify.dispatch current_exception\n  end\nend\n```\n\n## Support\n\nBackends that support the retrying of jobs are supported. A Runtime\nexception is raised if this concern is included in a job class with an\nunsupported backend.\n\nThe gem has only been tested with the Sidekiq backend. Please submit\npull-requests and issues for backends that do not function properly.\n\n## rescue_from Blocks With retry_job\n\nThe motivation of this gem is to play nicely with existing `rescue_from`\nblocks within your job classes. If a `rescue_from` block makes calls to\n`retry_job` is it probably best to call this method if and only if\n`retries_exhausted?` is not `true`. Otherwise, your jobs may be retried\nindefinitely! See this [test job\nclass](https://github.com/SimplyBuilt/activejob-retriable/blob/master/test/dummy/app/jobs/rescue_job.rb#L8)\nfor an example.\n\n## Exception Callbacks\n\nMuch like `ActiveJob` itself, retriable introduces some callbacks for\nexception handling. Your job class can define `before_exception`,\n`after_exception` and `around_exception` callbacks.\n\nRetriable will also set the value of `current_exception` to the actual\nexception. This way, direct access to the exception is possible from\nwithin a callback. This may be useful for error reporting and other\nneeds.\n\n## Retriable with ActionMailer\n\nIf you want `ActionMailer` delivery jobs to use `Retriable`, you have to\nreopen the `ActionMailer::DeliveryJob` class and manually include the\nconcern. For example:\n\n```ruby\nmodule ActionMailer\n  class DeliveryJob\n    include ActiveJob::Retriable\n  end\nend\n```\n\nIt is recommended to do this via an initializer. We're open to\nsuggestions on how to improve this aspect of `Retriable` though!\n\n## Advanced Usage\n\nIt is possible to overload or redefine both `retry_delay` and\n`retries_exhausted?` to include custom logic. This means it is easy to\nimplement different back-off strategies as well as more advanced\nexhausted logic.\n\nFeel free to open PR's with more advanced examples!\n\n## Testing\n\nThe default `ActiveJob::QueueAdapters::TestAdapter` does not call\nserialize and deserialize as one may expect. Thus, `retry_attempts` are\nnot properly tracked and \"infinite performs\" occur when an exception is\nraised. Therefore, we provided a new subclass to TestAdapter named\n`ActiveJob::Retriable::TestAdapter`. To use this adapter please do the\nfollowing:\n\n1. Include the `ActiveJob::Retriable::TestHelper` in your `test_helper.rb`\n\n```ruby\nrequire 'active_job/retriable/test_helper'\n```\n\n2. Reopen `ActiveJob::TestCase` and include the helper\n\n\n```ruby\nclass ActiveJob::TestCase\n  include ActiveJob::Retriable::TestHelper\nend\n```\n\n   Alternatively, you can just include the helper on a test-by-test\nbasis.\n\n3. If you're using ActiveJob assertions in controllers or elsewhere, be\n   sure to include the test helper concern there as well!\n\n4. *Optionally* add a setup and teardown block to toggle on\n   `reraise_when_retry_exhausted`, `print_exceptions_to_stderr` and\n`print_exception_backtraces_to_stderr`. These features are useful when\ntesting and debugging Active Jobs that raise exceptions or have syntax\nerrors.\n\n```ruby\nsetup do\n  ActiveJob::Retriable.reraise_when_retry_exhausted = true\n  ActiveJob::Retriable.print_exceptions_to_stderr   = true\n\n  # Or with a full backtrace...\n  # ActiveJob::Retriable.print_exceptions_to_stderr   = :backtrace\nend\n\nteardown do\n  ActiveJob::Retriable.reraise_when_retry_exhausted = false\n  ActiveJob::Retriable.print_exceptions_to_stderr   = false\nend\n```\n\nAdditionally, if you have jobs being enqueued in your `setup` blocks, it\nis highly recommended that you move that functionality to an\n`after_setup` method. This is due to how the default `TestHelper` works\nand may change in the future.\n\n## Adapter Notes \u0026 Tips\n\n- With **Sidekiq**, we highly encourage that you remove the RetryJobs\n  middleware. This can be done in an initializer with the following:\n\n```ruby\nSidekiq.configure_server do |config|\n  config.server_middleware.remove Sidekiq::Middleware::Server::RetryJobs\nend\n```\n\n## LICENSE\n\nThis project rocks and uses MIT-LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplybuilt%2Factivejob-retriable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplybuilt%2Factivejob-retriable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplybuilt%2Factivejob-retriable/lists"}