Sidekiq 作业 - return 在条件下失败或成功

Sidekiq job - return fail or success on condition

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

perform() 函数中调用 system('some_command') 总是 return 成功。

我想根据这样的条件让工作失败:

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

提前致谢

我想如果你只是抛出一个异常,它会让 sidekiq 作业失败:

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

当然,你应该用有意义的东西来代替我写的愚蠢的错误信息。

注意:unless xif !x 相同