I'm playing with delayed_job and I need to delete all the job with a specified handler value, I tried in this way
class Auction < ActiveRecord::Base
def clean_jobs
Delayed::Job.all.each do |job|
job.delete if job.payload_object.auction_id == id
end
end
end
and it works but I have to go through the entire queue...not cool. How can i work around this? Thank you
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.
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.
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.
You are using payload_object, which is a YAML text.
May be this code do the same thing.
Delayed::Job.where("handler LIKE '%auction_id: #{id}%'").delete_all
And for double check:
Delayed::Job.where("handler LIKE '%auction_id: #{id}%'").each do |job|
job.delete if job.payload_object.auction_id == id
end
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