优雅地停止芹菜任务 [英] Stopping celery task gracefully
问题描述
我想优雅地退出celery任务(即不通过调用 revoke(celery_task_id,Terminate = True)
)。我以为会向设置标志的任务发送消息,以便任务功能可以返回。与任务进行通信的最佳方法是什么?
I'd like to quit a celery task gracefully (i.e. not by calling revoke(celery_task_id, terminate=True)
). I thought I'd send a message to the task that sets a flag, so that the task function can return. What's the best way to communicate with a task?
推荐答案
为此使用信号。 Celery的 revoke
是正确的选择;它默认情况下使用SIGTERM,但是您可以指定其他如果愿意,可以使用 signal
参数。
Use signals for this. Celery's revoke
is the right choice; it uses SIGTERM by default, but you can specify another using the signal
argument, if you prefer.
只需在任务中为其设置信号处理程序(使用 signal
模块 ),可以正常终止任务。
Just set a signal handler for it in your task (using the signal
module) that terminates the task gracefully.
这篇关于优雅地停止芹菜任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!