sidekiq-silent-retry
is a middleware for Sidekiq that allows for silent retries of jobs. This gem intercepts exceptions raised during job execution and re-raises under a different exception class, so that tracing services can ignore them. Only the last exception is raised with the original exception.
Add this line to your application's Gemfile:
gem 'sidekiq-silent-retry'
And then execute:
$ bundle install
You can specify a custom error class for silent retries. This is useful for making error tracing services ignore these errors.
Create an initializer file (e.g., config/initializers/sidekiq_silent_retry.rb) and add the following:
Sidekiq::SilentRetry.silent_retry_error_class = MySilentRetryError
In your Sidekiq job class, configure the silent_retry option to control silent retries. The silent_retry option can be:
false
/nil
: Disabled (default).true
: Always enabled, no matter the error.- Some class / Array of classes: Only exceptions of said class(es) will be silently retried.
You can also set warn_after
option to start raise warnings after a number of retries instead of only the last one.
class MyJob
include Sidekiq::Job
sidekiq_options silent_retry: true
def perform(*args)
# Your job logic here
end
end
class MyJob
include Sidekiq::Job
sidekiq_options silent_retry: [CommonError, CommonError2], warn_after: 2
def perform(*args)
# Your job logic here
end
end
- Sidekiq 6.0 or later
Bug reports and pull requests are welcome on GitHub at https://github.com/trusted/sidekiq-silent-retry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Sidekiq::SilentRetry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.