Reputation: 7126
I need to run four tasks but they need to run one after the other only if they are successful.
I have tried to chain them like this..but they start off independently
res = (mul.si(5,5) | mul.si(5,6) | mul.si(5,7) | mul.si(5,8) | mul.si(5,9) )()
any idea?
Upvotes: 2
Views: 1704
Reputation: 1817
Yes you can do it. But you need to store the result as mentioned here.
But this is rarely used since it turns the asynchronous call into a synchronous one
In my example,
tasks.py is like
from celery import Celery
import datetime
app = Celery('tasks',backend='amqp' broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
def add_chained(args_list=list()):
for args in args_list:
print "Performing addtion for %s at %s" % (args, datetime.datetime.now())
result = add.delay(*args)
while not result.ready():
pass
Result is Like this:
>>> import tasks
>>> tasks.add_chained([(1,2), (2,3), (3,4), (4,5)])
Performing addtion for (1, 2) at 2014-01-17 18:49:57.392357
Performing addtion for (2, 3) at 2014-01-17 18:49:57.428961
Performing addtion for (3, 4) at 2014-01-17 18:49:57.432598
Performing addtion for (4, 5) at 2014-01-17 18:49:57.435891
Upvotes: 1