ruby-on-railsrubysidekiq

How to put a job to Dead using Sidekiq?


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

Solution

  • 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