如何使用 Sidekiq 将工作置为 Dead?

How to put a job to Dead using Sidekiq?

是否有可能在捕获作业中的错误时将此作业置于死机状态?

类似于:

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

根据 this question ...您不能在您的工作中动态地执行此操作。您最好的选择是将重试次数设置为零。

来自 documentation ...跳过重试,将失败的作业直接发送到死集:

class NonRetryableWorker
  include Sidekiq::Worker
  sidekiq_options retry: 0

  def perform(...)
  end
end