How can I delete specific jobs from Resque queue without clearing the whole queue?

Rami picture Rami · Apr 23, 2012 · Viewed 14.6k times · Source

I'm using Resque workers to process job in a queue, I have a large number of jobs > 1M in a queue and have some of the jobs that I need to remove ( added by error). Crating the queue with the jobs was not an easy tasks, so clearing the queue using resque-web and adding the correct jobs again is not an option for me.

Appreciate any advice. Thanks!

Answer

Puneeth picture Puneeth · Aug 7, 2012

To remove a specific job from queue you can use the destroy method. It's very easy to use, For example if you want to remove a job with class Post and id x, which is in queue named queue1 You can do like this..

Resque::Job.destroy(queue1, Post, 'x')

If you want to remove all the jobs of particular type from a queue you can use

Resque::Job.destroy(QueueName, ClassName) 

You can find it's documentation at

http://www.rubydoc.info/gems/resque/Resque%2FJob.destroy