芹菜工人细节

时间:2016-01-12 06:54:52

标签: python celery-task

我有芹菜任务,队列中有100个输入数据,需要使用5个工人执行。

  • 如何让哪个工作人员执行哪个输入?
  • 每个工作人员执行了多少输入及其状态?
  • 如果任何任务失败,如何单独获取失败的输入数据并使用可用的工作人员重新执行?

是否有任何可能的方法根据工人的具体情况定制芹菜。

我们可以结合芹菜工人限制和花

我没有使用任何框架。

2 个答案:

答案 0 :(得分:0)

  

如何让哪个工作人员执行哪个输入?

有两种选择可以使用多个工人:

  1. 使用单独的运行命令单独运行每个工作程序
  2. 使用命令行选项-c在一个命令中运行,即并发
  3. 第一种方法,花将支持它,并将向您显示所有工人,所有任务(您调用输入),哪个工作人员也处理了哪个任务和其他信息。

    使用第二种方法,flower将显示单个工作人员正在处理的所有任务。在这种情况下,您只能通过查看芹菜工作者生成的日志来区分,就像在日志中存储哪个工作者THREAD执行哪个任务一样。因此,我认为根据您的要求,您可以更好地使用第一个选项。

      

    每个工作人员执行了多少输入及其状态?

    正如我所提到的,使用第一种方法,花会给你这个信息。

      

    如果任何任务失败,如何单独获取失败的输入数据   用可用的工人重新执行?

    Flower确实提供过滤器来过滤失败的任务,并提供退出时返回的状态任务。您还可以设置芹菜应该重试失败任务的次数。但即使重试任务失败,您也必须自己重新启动任务。

答案 1 :(得分:0)

For the first and second question:

1) Using Flower API:
You can use celery flower to keep track of it. Flower api can provide you the information like which task is being executed by which worker through simple api calls (/api/task/info/<task_id>) 

2) Querying celery directly:
from celery import Celery
celery = Celery('vwadaptor', broker='redis://workerdb:6379/0',backend='redis://workerdb:6379/0')
celery.control.inspect().active()

3) Using celery events:
   Link : http://docs.celeryproject.org/en/latest/userguide/monitoring.html
   (look Real-time Processing)
   You can create an event  ( task created, task received, etc) and the response will have the worker name(hostname , see the link)

For the third question:
Use the config entry 'CELERY_ACKS_LATE=True' to retry failed tasks.
celery.conf.update(
    CELERY_ACKS_LATE=True,
)

You can also track failed tasks using celery events mentioned above and retry failed tasks manually.