celery中,我做这样的处理:
一个url经过a, b, c三个的函数,分别获得返回值,其中任意函数结果均与任意其他函数结果不相关,然后汇总起来,交给之后的流程.这样,我自然想到并行运行三个函数来加快处理速度.
然而由于一开始的设计问题, a函数式被设计成了一次可以处理多个url的形式,而一个一个的处理会非常慢.
@celery.task
def a(url_list):
'...do something...'
for url in url_list:
b.delay(url)
我尝试这样控制,然而任务似乎并不能嵌套.
那么,如何设计可以比较好的满足我这种比较奇怪的流程和要求呢?
A; b; c should be separated and written into 3 tasks. At the same time, a status value should be saved in the database to represent the execution status of the 3 tasks. After the execution of one task is completed, the status value should be modified and the other 2 should be checked. Whether each task is completed, if all are completed, the task results are summarized and then processed.
@xiaoboost Manual maintenance is feasible, but a bit time-consuming.
Celery can design the execution process, refer to the document: Designing Work-flows
The subject's needs can be solved with chords, and the value can be returned in the celery task.
BTW: Pay attention to several options related to return values in Celery configuration, such as this task_ignore_result