Question

When I try to use the example in Celery documentation which is add method with subtask, I can't get final result.

@task
def add(x, y, callback=None):
    result = x + y
    if callback:
        subtask(callback).delay(result)
    return result

When I call the task with;

>>> subadd = add.subtask(args=(5, ))
>>> r=add.apply_async(args=(1, 2,subadd))
>>> r.result
3

As it is seen, it returns 3 instead of 8.

There is an ERROR on a worker when I run these part. I don't know why it is happenning.

[2013-06-27 07:49:18,080: ERROR/MainProcess] Received unregistered task of type 'devicemanagement.celery_task.add'.

What should I do to get 8 from result?

Thank You!

Was it helpful?

Solution

Should it not be the following:

r = add.apply_async((1, 2), link=add.s(5))
r.result

Celery - Linking (callbacks/errbacks)

OTHER TIPS

In >3.0 celery, chain is another cool choice:

from celery import chain

r = chain(add.s(1, 2), add.s(5))()
#or using '|' operator
r = (add.s(1, 2) | add.s(1))()
r.result
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top