Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prioritize a job created with the delayed_jobs gem?

I am using the delayed_job gem like this:

Delayed::Job.enqueue Note.new(parameter_hash)

The jobs are processed by Heroku workers. I need to prioritize some jobs. I know there is a priority setting for delayed_job, but I'm not sure how to use it with the above job creation line.

How do I make a job higher priority?

like image 287
ben Avatar asked Jan 16 '11 03:01

ben


People also ask

How does a delayed job work?

Delayed::Job works by serializing a Ruby object as YAML and storing it in a database table so that a worker in a different process can retrieve, deserialize, and perform the requested work. Some operations that we use Delayed::Job for are longer-running data processing, sending emails, and updating search indicies.

What is delayed job in Rails?

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.


1 Answers

According to the docs, by default jobs are scheduled with a priority of 0--which is the highest priority. In this case, lower numbers have higher priorities.

To schedule some jobs at different priorities, use:

Delayed::Job.enqueue Note.new(parameter_hash), :priority => 10

Again, though, lower number = higher priority. A job with a priority of 0 is higher priority than one with 10.

like image 163
Andy Lindeman Avatar answered Oct 21 '22 21:10

Andy Lindeman