2016-01-12 52 views
3

我有芹菜任務,有100個輸入數據在隊列中,需要使用5名工人執行。芹菜工人詳細信息

  • 如何獲取哪個工作人員正在執行哪個輸入?
  • 每個工人都執行了多少個輸入及其狀態?
  • 如果任何任務失敗,如何分別獲取失敗的輸入數據並用可用的工作人員重新執行?

是否有任何可能的方式來定製芹菜根據工人的具體情況。

我們可以結合芹菜工人限制和花

我沒有使用任何框架。

回答

0

如何獲取哪個工作人員執行哪個輸入?

有2個選項使用多個工人:

  1. 您有獨立運行單獨運行每個工人命令
  2. 您在一個命令的命令行選項-c即併發運行

第一種方法,花會支持它,並會向您顯示所有工作人員,所有任務(您稱爲輸入),哪個工作人員處理了哪個任務以及其他信息。

用第二種方法,花會顯示單個工作人員正在處理的所有任務。在這種情況下,只能通過查看由芹菜工作人員生成的日誌來區分它,因爲它在日誌中存儲哪個工作線程執行了哪個任務。所以,我認爲根據您的要求,您會更好地使用第一個選項。

每個工人都執行了多少個輸入及其狀態?

正如我所提到的,使用第一種方法,花會給你這個信息。

如果任何任務是在分別與可用的工作 重新執行失敗怎麼能得到失敗的輸入數據?

Flower確實提供過濾器來過濾失敗的任務,並提供退出時返回的狀態任務。您也可以設置芹菜應該重試失敗任務的次數。但即使重試任務失敗後,您也必須自行重新啓動任務。

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.