How to fail the chain if it's sub task gives an exception
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles
--
Chapters
00:00 How To Fail The Chain If It'S Sub Task Gives An Exception
01:46 Answer 1 Score 0
02:01 Accepted Answer Score 16
02:38 Thank you
--
Full question
https://stackoverflow.com/questions/1266...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #django #rabbitmq #celery
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Magical Minnie Puzzles
--
Chapters
00:00 How To Fail The Chain If It'S Sub Task Gives An Exception
01:46 Answer 1 Score 0
02:01 Accepted Answer Score 16
02:38 Thank you
--
Full question
https://stackoverflow.com/questions/1266...
--
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.