Delayed Job creating Airbrakes every time it raises an error

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

When I raise "delayed RefundJob has failed" in the else statement, it creates an Airbrake. I want to run the job again if it ends up in the else section.

Is there any way to re-queue the job without raising an exception? And prevent creating an airbrake?

I am using delayed_job version 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.


DelayedJob expects a job to raise an error to requeued, by definition.

From there you can either :

  • Ignore your execpetion on airbrake side, see https://github.com/airbrake/airbrake#filtering so it still gets queued again without filling your logs
  • Dive into DelayedJob code where you can see on https://github.com/tobi/delayed_job/blob/master/lib/delayed/job.rb#L65 that a method named reschedule is available and used by run_with_lock ( https://github.com/tobi/delayed_job/blob/master/lib/delayed/job.rb#L99 ). From there you can call reschedule it manually, instead of raising your exception.
  • About the later solution, I advise adding some mechanism that still fill an airbrake report on the third or later try, you can still detect that something is wrong without the hassle of having your logs filled by the attempts.

    链接地址: http://www.djcxy.com/p/11274.html

    上一篇: 使用Java 1.5获取Windows中以太网适配器的IPv4地址

    下一篇: 每次产生错误时延迟创建Airbrakes作业