Hey all! Simple question: if I raise an error within a task (i.e.,
ValueError
) 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:
Copy code
# 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: ...
k
Kevin Kho
03/25/2022, 7:30 PM
Try retrieving it with
new_state.result
d
Danny Vilela
03/25/2022, 7:32 PM
Ohhhhhh okay. I can test it out real quick, but do you know if
new_state.result
would be the
ValueError
itself?
k
Kevin Kho
03/25/2022, 7:33 PM
I think it is, maybe as JSON. I can test in a bit too
🙌 1
Kevin Kho
03/25/2022, 7:35 PM
Copy code
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()
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.