本文介绍了将n个任务添加到芹菜队列中,等待结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将添加多个任务到芹菜队列并等待结果。我有各种各样的想法,我将如何实现这一点使用某种形式的共享存储(memcached,redis,db等),但是,我认为这是Celery可以自动处理,但我找不到任何在线资源。 / p>
代码示例
def do_tasks b): for a in b: c.delay(a) return c.all_results_some_how()解决方案
对于 Celery> = 3.0 ,TaskSet是已弃用,赞成组。
从芹菜进口组从任务导入添加 job = group([ add.s(2,2), add.s(4,4), add.s(8,8), add.s(16,16), add.s(32,32), ])等待:
result = job.apply_async() result.join()
I would add multiple tasks to celery queue and wait for results. I have various ideas how I would achieve this utilising some form of shared storage (memcached, redis, db, etc.), however, I would have thought it's something that Celery can handle automatically but I can't find any resources online.
Code example
def do_tasks(b): for a in b: c.delay(a) return c.all_results_some_how()解决方案
For Celery >= 3.0, TaskSet is deprecated in favour of group.
from celery import group from tasks import add job = group([ add.s(2, 2), add.s(4, 4), add.s(8, 8), add.s(16, 16), add.s(32, 32), ])Wait:
result = job.apply_async() result.join()
更多推荐
将n个任务添加到芹菜队列中,等待结果
发布评论