15

我用 redis 添加了task一些celery错误broker

但现在我想删除不正确的task,我找不到任何方法来做到这一点

是否有一些命令或一些 api 可以做到这一点?

4

5 回答 5

29

我知道这样做的两种方法:

1) 直接从代理中删除队列。在你的情况下,它是 Redis。有两个命令可以帮助您:llen(查找正确的队列)和del(删除它)。

2) 使用--purge--discard选项启动 celery worker。这是帮助:

--purge, --discard    Purges all waiting tasks before the daemon is started.
                      **WARNING**: This is unrecoverable, and the tasks will
                      be deleted from the messaging server.
于 2013-06-22T12:07:57.577 回答
3

最简单的方法是使用celery control revoke [id1 [id2 [... [idN]]]](也不要忘记传递-A project.application标志)。其中 id1 到 idN 是任务 ID。但是,出于正当理由,不能保证每次运行它都会成功...

当然 Celery 有它的 API。这是一个如何从脚本执行此操作的示例:res = app.control.revoke(task_id, terminate=True)

在上面app的示例中是 Celery 应用程序的一个实例。

在极少数情况下,上面的控制命令不起作用,在这种情况下,您必须指示 Celery worker 杀死工作进程:res = app.control.revoke(task_id, terminate=True, signal='SIGKILL')

于 2020-05-07T10:49:29.243 回答
2

我刚遇到这个问题,所以对于未来的读者,

http://celery.readthedocs.org/en/latest/faq.html#i-ve-purged-messages-but-there-are-still-messages-left-in-the-queue

因此,要正确清除等待任务的队列,您必须停止所有工作人员,然后使用 celery.control.purge() 清除任务。

于 2015-07-01T00:23:14.740 回答
1

1.要正确清除等待任务的队列,您必须停止所有工作人员(http://celery.readthedocs.io/en/latest/faq.html#i-ve-purged-messages-but-there-are-仍然消息留在队列中):

2 ...然后从特定队列中清除任务:

$ cd <source_dir
$ celery amqp queue.purge <queue name>

3. 重新启动工人

于 2017-03-27T15:28:55.683 回答
0

尝试删除 .state 文件,如果您使用的是节拍工作者(芹菜工作者 -B),那么也删除计划文件

于 2020-05-07T10:42:57.383 回答