Hello everyone. Is there a way to customize the final message of the flow ? Currently it only says
Copy code
====== final results: <Success: "All reference tasks succeeded.">
or
====== final results: <Failed: "Some reference tasks failed.">
We have different types of successes/failures. Currently we could not differentiate them from the flow hook notification message. We would like to set customized messages to different scenarios and react differently.
for example
Copy code
====== final results: <Failed: "Task_A failed due to timeout.">
z
Zanie
03/03/2021, 12:25 AM
Hi -- off the top of my head you can use a flow-level state handler to do this e.g.
Copy code
import prefect
from prefect.engine.state import Success
from prefect import Flow, task
def update_final_state(flow, old_state, new_state):
if isinstance(new_state, Success):
new_state.message = "Hello world!"
print(f"At state: {new_state}")
return new_state
@task
def do_nothing():
pass
with Flow("example-flow-final-state", state_handlers=[update_final_state]) as flow:
do_nothing()
flow.run()
but the final state of the flow may be a special case so I'm not sure it'll be reflected in the UI
Zanie
03/03/2021, 12:44 AM
Someone on my team checked and this state update is sent to the UI
Zanie
03/03/2021, 12:44 AM
I do not think task states can be inspected from the flow state handler though so I'm not sure it would fit your use-case entirely.
h
Hui Zheng
03/03/2021, 2:00 AM
Is there a way to send out flow state notification with some customized field or message based on the result of a task?
Hui Zheng
03/03/2021, 2:02 AM
Any recommendations to allow our monitor and alert system to differentiate different kinds of failures from one flow? So that we could react differently.
z
Zanie
03/03/2021, 2:58 AM
You can implement task state handlers that send a notification and attach them to specific tasks (or all tasks)
Zanie
03/03/2021, 2:58 AM
I'll also open a feature request for this as I think it's a very reasonable desire
🙌 1
h
Hui Zheng
03/03/2021, 5:22 AM
Yes, I also think about this work-around of attach notification to task state. However, we built all our monitoring and alert system based on Prefect Cloud Flow Run Hook notification, which is associated with flow state. It’s a big change to switch it all to task level notification.
Hui Zheng
03/03/2021, 5:23 AM
Thank you for making the feature request. I would love to follow that and maybe contribute to it.
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.