1

Is it possible, when catching an error in a job, to put this job in dead?

Something like:

class MyJob < ApplicationJob
  queue_as :default
  sidekiq_options retry: 5

  rescue_from MyError do
    # This is where I have to put the job in dead.
  end

  def perform(document)
    ...
  end
end
RomanOks
  • 692
  • 3
  • 13
  • If your intention is to just stop the job from retrying ... why not just return true and allow it to be marked as complete? – Jon Nov 03 '21 at 07:52
  • @Jon For these errors, I need to put the job in dead so that it can be tracked there. I also need to notify the support about all jobs from dead. – RomanOks Nov 03 '21 at 08:01
  • Then I'd recommend using something like sentry.io to do this rather than manually monitoring the dead queue. You can configure `death_handlers` to handle this for you. – Jon Nov 03 '21 at 08:03

1 Answers1

0

As per this question ... you cannot dynamically do this within your job. Your best option would be to set the retries to zero.

From the documentation ... Skip retries, send a failed job straight to the Dead set:

class NonRetryableWorker
  include Sidekiq::Worker
  sidekiq_options retry: 0

  def perform(...)
  end
end
Jon
  • 10,678
  • 2
  • 36
  • 48