Hui Zheng
03/10/2021, 12:29 AMretries=3
for a task_A, we want to retry task_A for up to 3 times when it fails due to some network connection issue or intermittent failures. Meanwhile, however, we have the logic in the task_A
that explicitly and intentionally raise FAIL_A
signal for downstream tasks. That FAIL_A
is not meant to be re-tried by task_A
. When task_A
encounters this intentional FAIL_A
, it shall skip retries and return it directly. How could I do that?Chris White
Hui Zheng
03/10/2021, 12:36 AMChris White
Failed
-> Retrying
and, if the Failed state has a FAIL
signal attached to it it prevents the task from entering a Retrying
state:
def retry_handler(t, old, new):
if new.is_retrying() and isinstance(old.result, FAIL):
return Failed("No retries allowed")
Here’s a simple example; if you remove the state handler you’ll see the task retry 3 times, but with the handler it fails immediately:
@task(max_retries=3, retry_delay=timedelta(0), state_handlers=[retry_handler])
def fail():
raise FAIL("failed")
f = Flow("test", tasks=[fail])
f.run()
Hui Zheng
03/10/2021, 12:40 AMChris White
Marvin
03/10/2021, 12:41 AMHui Zheng
03/10/2021, 12:42 AMChris White
FAIL
signal almost universally implies bypassing retries — if someone wants to retry they can instead raise a retrying signal….Hui Zheng
03/10/2021, 12:52 AMtask_A
with timeout=20. In the case of task timeout, it will raise a TimeoutError
exception (not a signals.FAIL) . In this situation, will the task_A
attempts retries?Chris White
Hui Zheng
03/10/2021, 12:56 AMChris White
Hui Zheng
03/10/2021, 1:15 AMstate.Failed
and signals.Fail
. I assume signals.Fail
is just a special type of exception. When I raise signals.Fail
in task_A, there is specific failure message and failure result that I want to pass to downstream models. Could I pass the message and result of the signals.Fail
to the downsteam models like this?
def skip_retries_on_signal_fail(task, old_state, new_state):
if new_state.is_retrying() and isinstance(old_state.result, signals.FAIL):
return state.Failed(
message=old_state.message,
result=old_state.result)
Chris White
raise FAIL(message="Hui's message", result="Hui's special result")
and within your state handler check for Hui’s special result as the .result
attribute of the old state, instead of the exception typeChris White
Hui Zheng
03/16/2021, 6:46 PM