How to fail the chain if it's sub task gives an exception
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 Question
01:59 Accepted answer (Score 15)
02:51 Answer 2 (Score 0)
03:12 Thank you
--
Full question
https://stackoverflow.com/questions/1266...
Answer 1 links:
[documentation says you shouldn't]: http://ask.github.com/celery/cookbook/ta...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #rabbitmq #celery
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 Question
01:59 Accepted answer (Score 15)
02:51 Answer 2 (Score 0)
03:12 Thank you
--
Full question
https://stackoverflow.com/questions/1266...
Answer 1 links:
[documentation says you shouldn't]: http://ask.github.com/celery/cookbook/ta...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #rabbitmq #celery
#avk47
ACCEPTED ANSWER
Score 16
When you have a chain:
>>> c = a.s() | b.s() | c.s()
>>> res = c()
>>> res.get()
Calling the chain will generate unique id's for all of the task in the chain, send the messages and return the last result in the chain.
So when you do res.get() you are simple trying to retrieve the result of the last task in the chain.
It will also decorate the results with parent attributes, which you can traverse to get the progress of the chain:
>>> res # result of c.s()
>>> res.parent # result of b.s()
>>> res.parent.parent # result of a.s()
If you want to check for errors along the way you can do:
def nodes(node):
while node.parent:
yield node
node = node.parent
yield node
values = [node.get(timeout=1) for node in reversed(list(nodes(res)))]
value = values[-1]
ANSWER 2
Score 0
Actually I think you shouldn't be using raise here.
You're throwing an exception, when the documentation says you shouldn't, you might want to just use err.retry and not raise err.retry.