从子组中获取子任务的结果

时间:2017-02-13 19:16:20

标签: python celery

我是Celery的新手,我的一些概念对我来说还不是很清楚。我试图解决another problem,并且到目前为止得到了一个更小且可运行的代码片段,它的功能类似于我想要实现的功能。现在我不明白是否有可能通过执行下面的链获得最终结果,这应该是一个类似的数组:

["[MARY]", "[HAD]", "[A]", "[LITTLE]", "[LAMB]"](无论什么顺序)?

由于

import celery
from celery import subtask

app = celery.Celery('celtest', backend='redis://localhost', broker='pyamqp://guest@localhost')

@app.task
def taskThatReturnsArray():
    return ["Mary", "Had", "A", "Little", "Lamb"]

@app.task
def taskThatAddsBrackets(string):
    return "[%s]" % string

@app.task
    def taskThatProcessesItems(item):
        chain = celery.chain(
            taskThatUppercasesString.s(item),
            taskThatAddsBrackets.s()
        )
        return chain()

@app.task
def taskThatUppercasesString(string):
    return string.upper()

@app.task
def dmap(it, callback):
    callback = subtask(callback)
    return celery.group(callback.clone([arg,]) for arg in it)()

if __name__ == '__main__':
    chain = celery.chain(
        taskThatReturnsArray.s(),
        dmap.s(taskThatProcessesItems.s())
    )
    res = chain()

0 个答案:

没有答案