如何销毁由 resque 工作人员排队的工作?
我在 Rails-3 项目上使用 Resque 来处理计划每 5 分钟运行一次的作业。我最近做了一些事情,使这些工作岗位的创造如滚雪球般增长,目前该堆栈已达到 1000 多个工作岗位。我修复了导致许多作业排队的问题,现在我遇到的问题是由错误创建的作业仍然存在,因此测试某些内容变得很困难,因为一个作业被添加到具有 1000 多个作业的队列中。 我似乎无法停止这些工作。我尝试使用flushall命令从redis-cli中删除队列,但它不起作用。我错过了什么吗?因为我似乎找不到摆脱这些工作的方法。
I'm using Resque on a rails-3 project to handle jobs that are scheduled to run every 5 minutes. I recently did something that snowballed the creation of these jobs and the stack has hit over 1000 jobs. I fixed the issue that caused that many jobs to be queued and now the problem I have is that the jobs created by the bug are still there and therefore It becomes difficult to test something since a job is added to a queue with 1000+ jobs.
I can't seem to stop these jobs. I have tried removing the queue from the redis-cli using the flushall command but it didn't work. Am I missing something? coz I can't seem to find a way of getting rid of these jobs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
根据上述答案,如果您需要清除所有队列,可以使用以下命令:
Playing off of the above answers, if you need to clear all of your queues, you could use the following:
如果您弹出 Rails 控制台,则可以运行以下代码来清除队列:
If you pop open a rails console, you can run this code to clear out your queue(s):
Resque 已经有一个方法可以做到这一点 - 尝试
Resque.remove_queue(queue_name)
(请参阅文档 这里)。它在内部执行Resque.redis.del()
,但它也执行其他清理工作,并且通过使用 api 方法(而不是假设 resque 如何工作),您将更加面向未来。Resque already has a method for doing this - try
Resque.remove_queue(queue_name)
(see the documentation here). Internally it performsResque.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.更新了用于清理的 rake 任务(根据最新的 redis 命令更改):https://gist.github.com/1228863
Updated rake task for clearing (according to latest redis commands changes): https://gist.github.com/1228863
现在是这样的:
This is what works now:
使用 Resque API 比删除 Resque 的 Redis 上的所有内容更安全、更可靠。 Resque 在内部做了一些清洁工作。
如果要删除所有队列和关联的排队作业:
下次作业排队时将重新创建队列。
文档
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:
The queues will be re-created the next time a job is enqueued.
Documentation
进入redis控制台:
列出数据库:
“resque:queue:your_overloaded_queue”
- 您需要的数据库。然后运行:
或者,如果您想删除队列中的指定作业,则使用
LRANGE
命令:然后将一个值复制/粘贴到
LREM
命令:其中 5 - 数量要删除的元素。
Enter redis console:
List databases:
"resque:queue:your_overloaded_queue"
- db which you need.Then run:
Or if you want to delete specified jobs in queue then list few values from db with
LRANGE
command:Then copy/paste one value to
LREM
command:Where 5 - number of elements to remove.