Reputation: 4700
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!
Upvotes: 1
Views: 2019
Reputation: 299
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
Upvotes: 1
Reputation: 3556
Should it not be the following:
r = add.apply_async((1, 2), link=add.s(5))
r.result
Celery - Linking (callbacks/errbacks)
Upvotes: 2