Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually Retry Job in Delayed_job

Delayed::Job's auto-retry feature is great, but there's a job that I want to manually retry now. Is there a method I can call on the job itself like...

Delayed::Job.all[0].perform

or run, or something. I tried a few things, and combed the documentation, but couldn't figure out how to execute a manual retry of a job.

like image 759
Michael Waxman Avatar asked Jul 22 '10 18:07

Michael Waxman


People also ask

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.

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 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.


3 Answers

To manually call a job

Delayed::Job.find(10).invoke_job # 10 is the job.id

This does not remove the job if it is run successfully. You need to remove it manually:

Delayed::Job.find(10).destroy
like image 77
The Who Avatar answered Oct 02 '22 16:10

The Who


Delayed::Worker.new.run(Delayed::Job.last)

This will remove the job after it is done.

like image 43
Beena Shetty Avatar answered Oct 02 '22 16:10

Beena Shetty


You can do it exactly the way you said, by finding the job and running perform.

However, what I generally do is just set the run_at back so the job processor picks it up again.

like image 42
Joe Martinez Avatar answered Oct 02 '22 16:10

Joe Martinez