如何让芹菜用同一个工人重试? [英] How to make celery retry using the same worker?
问题描述
您可以让每个celeryd实例从名为worker的主机名称的队列中消耗:
celeryd -l info -n worker1.example.com -Q celery,worker1.example.com
将主机名设置为 worker1.example.com
,并将从名为相同的队列,以及默认队列(名为 celery
)。
然后将任务指向您可以使用的具体工作人员:
task.apply_async(args,kwargs,queue =worker1.example.com)
直接重试:
task.retry(queue =worker1.example.com)
或指导重试到同一个工作人员:
task.retry(queue = task.request.hostname)
I'm just starting out with celery in a Django project, and am kinda stuck at this particular problem: Basically, I need to distribute a long-running task to different workers. The task is actually broken into several steps, each of which takes considerable time to complete. Therefore, if some step fails, I'd like celery to retry this task using the same worker to reuse the results from the completed steps. I understand that celery uses routing to distribute tasks to certain server, but I can't find anything about this particular problem. I use RabbitMQ as my broker.
You could have every celeryd instance consume from a queue named after the hostname of the worker:
celeryd -l info -n worker1.example.com -Q celery,worker1.example.com
sets the hostname to worker1.example.com
and will consume from a queue named the same, as well as the default queue (named celery
).
Then to direct a task to a specific worker you can use:
task.apply_async(args, kwargs, queue="worker1.example.com")
similary to direct a retry:
task.retry(queue="worker1.example.com")
or to direct the retry to the same worker:
task.retry(queue=task.request.hostname)
这篇关于如何让芹菜用同一个工人重试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!