如何让芹菜用同一个工人重试? [英] How to make celery retry using the same worker?

查看:160
本文介绍了如何让芹菜用同一个工人重试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Django项目中开始使用芹菜,而且有些困扰着这个特殊的问题:基本上,我需要将一个长期运行的任务分配给不同的工作人员。这个任务实际上分为几个步骤,每个步骤都需要相当长的时间才能完成。因此,如果某些步骤失败,我希望芹菜使用同一个工作人员重新执行此任务,以便重复使用完成步骤的结果。我知道芹菜使用路由将任务分发到某些服务器,但是我找不到任何关于这个特定问题的东西。我使用RabbitMQ作为我的经纪人。

解决方案

您可以让每个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆