Danny Vilela
03/25/2022, 7:29 PMValueError
) is it possible to recover that traceback/error from a state handler? Right now I can say “this task failed and will be retrying in X minutes”, but not “this task failed for reason Y and will retry in X minutes”. Or can we pass keyword arguments to a state handler with this signature:
# What I have now.
def notify_on_retry(task: Task, old_state: State, new_state: Retrying) -> State: ...
# Maybe what I want?
def notify_on_retry(task: Task, old_state: State, new_state: Retrying, message: str) -> State: ...
# Alternative?
def notify_on_retry(task: Task, old_state: State, new_state: Retrying, **kwargs) -> State: ...
Kevin Kho
new_state.result
Danny Vilela
03/25/2022, 7:32 PMnew_state.result
would be the ValueError
itself?Kevin Kho
from prefect import Flow, task
import prefect
def handler(obj, old_state, new_state):
if new_state.is_failed():
<http://prefect.context.logger.info|prefect.context.logger.info>(new_state.result)
return new_state
@task(state_handlers=[handler])
def abc():
raise ValueError("MESSAGE HERE")
with Flow(",,") as flow:
abc()
flow.run()
type(new_state.result)
also. and you can pull the exception message with new_state.result.message
I thinkAnna Geller