To call a function on every flow run state change,...
# ask-marvin
m
To call a function on every flow run state change, you can use state change hooks in Prefect. These hooks execute code in response to changes in flow or task run states, enabling you to define actions for specific state transitions in your workflow. Here's a simple example of how to define a hook function:
Copy code
python
from prefect import flow

def my_success_hook(flow, flow_run, state):
    print(f"Flow run {flow_run.id} finished with state {state}")
You would then attach this hook to a flow state handler when defining your flow. For more details on state change hooks and examples, you can refer to the Prefect documentation: - State Change Hooks - Final state determination Remember, the above code snippet is a starting point. You'll need to flesh it out with your specific logic for handling various state changes.