In my opinion this is a common use-case that doesn't get enough love in the documentation.
Assuming you want to abort a chain mid-way while still reporting SUCCESS as status of the completed tasks, and not sending any error log or whatnot (else you can just raise an exception) then a way to accomplish this is:
@app.task(bind=True) # Note that we need bind=True for self to work
def task1(self, other_args):
#do_stuff
if end_chain:
self.request.callbacks = None
return
#Other stuff to do if end_chain is False
So in your example:
@app.task(ignore_result=True, bind=True)
def is_room_open(self, args_sub_1):
#something time consuming
if http_req_and_parse(args_sub_1):
# go on and do the notify task
return True
else:
self.request.callbacks = None
Will work. Note that instead of ignore_result=True
and subtask()
you can use the shortcut .si()
as stated by @abbasov-alexander
Edited to work with EAGER mode, as suggested by @PhilipGarnero in the comments.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…