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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With