将n个任务添加到芹菜队列中,等待结果 [英] Add n tasks to celery queue and wait for the results

查看:135
本文介绍了将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个任务添加到芹菜队列中,等待结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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