Posted 5 months ago. Visible to the public. Repeats. Linked content.

Heads up: Sidekiq per default silently fails when retries are exhausted!

For Sidekiq to be able to retry your jobs it has to be able to catch errors that occur while a job is executed.

Per default, Sidekiq will not raise / notify you if the retry count is exhausted. It will only copy the job to the dead queue (see wiki).

If you want to get notified, you have to implement it in your worker explicitly with a sidekiq_retries_exhausted-block, e.g. like this:

Copy
class DownloadWorker include Sidekiq::Worker # Import jobs are retried a few times without sending exception notifications. # Only after the configured retries are exhausted we send a notification. That # way we are only notified about permanent issues. sidekiq_retries_exhausted do |error_info, exception| ExceptionNotifier.notify_exception exception, data: { sidekiq: error_info } end def perform(record_class, record_id) # ... end end

Since v 5.1, there is also a way to configure this globally.

Be aware, that if you use the standard count for retries it will take a while until you are notified of your error (~21 days). You could also send a notification each third retry or use less retries.

Also, if you make thousands of calls to an API it may not be wise to send emails if the API is down. Instead you could implement sending an error notification if the data (in the db) is too old.

Testing:

  • If you use sidekiq_retries_exhausted (unit test): https://stackoverflow.com/questions/33930199/rspec-sidekiq-how-to-test-within-sidekiq-retries-exhausted-block-with-another
  • If you use the global option (manual test):
Copy
# Use this worker to test if the exception notifier for sidekiq works as expected and the retries total duration fits. # Example: TestWorker.perform_async('foo', 'bar') class TestWorker include Sidekiq::Worker def perform(*args) raise 'This is a test error. All is well.' end end

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Judith Roth
Last edit:
2 months ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Judith Roth to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more