Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 930
Syed Usamah Avatar asked Oct 09 '12 17:10

Syed Usamah


People also ask

What is delayed job?

Delayed Job, also known as DJ, makes it easy to add background tasks to your Rails applications on Heroku. You can also use Resque and many other popular background queueing libraries. Delayed Job uses your database as a queue to process background jobs.

How do you restart a delayed job?

Restart Delayed Job on deploy You must remove that one now if you have it. It basically does the same thing that we will add now but without using upstart. We will now create a new file that will host our start, stop and restart tasks. Create a file at lib/capistrano/tasks/delayed_job.

How do I know if my job is running late?

The most simple way to check whether delayed_job is running or not, is to check at locked_by field. This field will contain the worker or process locking/processing the job. Running Delayed::Job. where('locked_by is not null') will give you some results, if there are jobs running.


2 Answers

The cleanest way would be to re-queue, i.e. create a new job and enqueue it, and then exit the method normally.

like image 140
Roman Avatar answered Sep 21 '22 13:09

Roman


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.

like image 33
Uri Agassi Avatar answered Sep 19 '22 13:09

Uri Agassi