How to destroy jobs enqueued by resque workers?

…衆ロ難τιáo~ 提交于 2019-12-02 14:39:11
Dylan Markow

If you pop open a rails console, you can run this code to clear out your queue(s):

queue_name = "my_queue"
Resque.redis.del "queue:#{queue_name}"

Playing off of the above answers, if you need to clear all of your queues, you could use the following:

Resque.queues.each{|q| Resque.redis.del "queue:#{q}" }
iainbeeston

Resque already has a method for doing this - try Resque.remove_queue(queue_name) (see the documentation here). Internally it performs Resque.redis.del(), but it also does other cleanup, and by using an api method (rather than making assumptions about how resque works) you'll be more future-proof.

Updated rake task for clearing (according to latest redis commands changes): https://gist.github.com/1228863

This is what works now:

Resque.remove_queue("...")

Enter redis console:

redis-cli

List databases:

127.0.0.1:6379> KEYS *
 1) "resque:schedules_changed"
 2) "resque:workers"
 3) "resque:queue:your_overloaded_queue"

"resque:queue:your_overloaded_queue" - db which you need.

Then run:

DEL resque:queue:your_overloaded_queue

Or if you want to delete specified jobs in queue then list few values from db with LRANGE command:

127.0.0.1:6379> LRANGE resque:queue:your_overloaded_queue 0 2
1) "{\"class\":\"AppClass\",\"args\":[]}"
2) "{\"class\":\"AppClass\",\"args\":[]}"
3) "{\"class\":\"AppClass\",\"args\":[]}"

Then copy/paste one value to LREM command:

127.0.0.1:6379> LREM resque:queue:your_overloaded_queue 5 "{\"class\":\"AppClass\",\"args\":[]}"
(integer) 5

Where 5 - number of elements to remove.

It's safer and bulletproof to use the Resque API rather than deleting everything on the Resque's Redis. Resque does some cleaning in the inside.

If you want to remove all queues and associated enqueued jobs:

Resque.queues.each {|queue| Resque.remove_queue(queue)}

The queues will be re-created the next time a job is enqueued.

Documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!