7
def perform
  refund_log = {
    success: refund_retry.success?,
    amount: refund_amount,
    action: "refund"
  }
  if refund_retry.success?
    refund_log[:reference] = refund_retry.transaction.id
    refund_log[:message] = refund_retry.transaction.status
  else
    refund_log[:message] = refund_retry.message
    refund_log[:params] = {}
    refund_retry.errors.each do |error|
      refund_log[:params][error.code] = error.message
    end
    order_transaction.message = refund_log[:params].values.join('|')
    raise "delayed RefundJob has failed"
  end
end

当我在 else 语句中提出“延迟的 RefundJob 失败”时,它会创建一个Airbrake。如果它在 else 部分结束,我想再次运行该作业。

有没有办法在不引发异常的情况下重新排队工作?并防止产生空气制动?

我正在使用延迟作业版本 1。

4

3 回答 3

2

最干净的方法是重新排队,即创建一个新作业并将其排队,然后正常退出该方法。

于 2012-10-10T16:47:43.937 回答
1

To elaborate on @Roman's response, you can create a new job, with a retry parameter in it, and enqueue it.

If you maintain the retry parameter (increment it each time you re-enqueue a job), you can track how many retries you made, and thus avoid an endless retry loop.

于 2014-04-08T14:22:22.953 回答
0

根据定义,DelayedJob 期望作业引发错误以重新排队。

从那里您可以:

关于后面的解决方案,我建议添加一些机制,在第三次或以后的尝试中仍然填充空气制动报告,您仍然可以检测到有问题,而无需通过尝试填充日志的麻烦。

于 2012-10-10T12:55:39.980 回答