【问题标题】:Sidekiq job - return fail or success on conditionSidekiq 作业 - 在条件下返回失败或成功
【发布时间】:2015-10-29 19:33:50
【问题描述】:

如何以编程方式让 Sidekiq 中的作业失败?

perform() 函数内调用system('some_command') 始终返回成功的作业。

我想基于这样的条件让工作失败:

def perform(data)
  output = system('some_command')
  if output
    # return this job as :success
  else
    # return this job as :fail
  end
end

提前致谢

【问题讨论】:

    标签: ruby sinatra sidekiq


    【解决方案1】:

    我认为如果你只是提出一个异常,它会使 sidekiq 工作失败:

    def perform(data)
      output = system('some_command')
      raise StandardError, "my error is so sexy" unless output
    end
    

    当然,你应该把我写的愚蠢的错误信息替换成有意义的东西。

    注意:unless xif !x 相同

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多