您能否解释一下我必须使用什么:task_reject_on_worker_lost
或 task_acks_late
以及它们有何不同?
为什么当task_acks_late为True时,Celery在异常后不再次运行任务?
在 Celery 文档中:
Even if task_acks_late is enabled, the worker will acknowledge tasks when the worker process executing them abruptly exits
“突然退出”是什么意思?会引发异常吗?
当 task_acks_late
为 True
且 task_reject_on_worker_lost
为 True
时,Celery 何时重试任务?
最佳答案
如果您希望它在异常后重试,您可以将参数传递给装饰器。
@app.task(max_retries=10)
def task(*args, **kwargs):
#stuff
突然退出是指worker被杀死,并非异常(exception)。如果您使用task_acks_late,那么工作人员将在任务结束时而不是开始时从队列中删除该项目。但是,如果工作进程被终止,即使任务尚未完成,任务仍然会被确认。如果发生上述事件,task_reject_on_worker_lost
将重新排队消息,这样您就不会丢失任务。
http://docs.celeryproject.org/en/latest/userguide/configuration.html#task-acks-late
您应该能够毫无问题地使用这两个设置。
关于python - Celery中的task_reject_on_worker_lost和task_acks_late有什么不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45045980/