[英]how to remove task from celery with redis broker?
我用 redis broker
向celery
添加了一些錯誤的task
但現在我想刪除不正確的task
,我找不到任何方法來做到這一點
是否有一些命令或一些 api 來做到這一點?
我知道這樣做的兩種方法:
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.
最簡單的方法是使用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')
工作進程: res = app.control.revoke(task_id, terminate=True, signal='SIGKILL')
我剛剛遇到了這個問題,所以對於未來的讀者,
因此,要正確清除等待任務的隊列,您必須停止所有工作人員,然后使用 celery.control.purge() 清除任務。
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. 重新開始工作
嘗試刪除 .state 文件,如果您使用的是 beat worker(celery worker -B),那么也刪除 schedule 文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.