wachichornia
wachichornia

Reputation: 1188

Sidekiq/Rails: How to catch exception AND retry

I have sidekiq jobs running Selenium. If the job crashes, I need to

  1. catch the exception to shut down the selenium driver (otherwise all coming jobs will crash as well),
  2. notify error handler (Sentry)
  3. Have sidekiq try again

Today I can catch and notify, but by catching the exception Sidekiq will not retry the job.

My question is similar to this one but a) it got no answer and b) that user did not want to notify its error handling service.

How do I get Sidekiq to retry the job even though I catch the exception?

Upvotes: 1

Views: 3918

Answers (1)

Marek Lipka
Marek Lipka

Reputation: 51161

How about re-raising exception? It would be something like this:

def perform
  # perform_code
rescue ErrorClass => error
  # handle error
  raise error
end

This way, sidekiq is gonna repeat this task (because it raises an error), but the handling code will also be executed.

Upvotes: 5

Related Questions