如何完成Sidekiq工作?

时间:2014-05-09 18:41:53

标签: ruby-on-rails sidekiq

假设我有一个看起来像这样的工人类:

class BuilderWorker
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform(order_id)
    if(order_id == 5)
      # How can I finish the job here? Say I want to finish it with a status of FAIL or COMPLETE.
    end
  end
end

我正在寻找一种方法来完成一个来自Worker类的工作,并在完成后给它状态为FAILED。完成应该是安静的(不提出异常)

1 个答案:

答案 0 :(得分:1)

使用Sidekiq只有两个工作结果:

  • 成功 - 作业从执行方法返回而没有错误
  • 失败 - 作业引发错误,进入重试队列以便将来重试

您的复杂场景称为应用程序逻辑,Sidekiq无法提供它。写下这个逻辑取决于你。