Hello everyone. Is there a way to customize the fi...
# ask-community
h
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
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
Someone on my team checked and this state update is sent to the UI
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
Is there a way to send out flow state notification with some customized field or message based on the result of a task?
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
You can implement task state handlers that send a notification and attach them to specific tasks (or all tasks)
I'll also open a feature request for this as I think it's a very reasonable desire
🙌 1
h
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.
Thank you for making the feature request. I would love to follow that and maybe contribute to it.
j
👌
h
Thank youi