Blake
03/03/2024, 8:30 PMRunning
. How can I go about setting the state of my flow_run to be Completed
in my on_completion method when I check that it is still listed as Running
?Marvin
03/03/2024, 8:31 PMon_completion
method is intended to be used for hooks that run when a flow completes, but it doesn't actually set the state of the flow run; it reacts to the flow run reaching a particular state.
If over half of your flow runs are being recorded as still in the Running
state, then they likely haven't actually completed yet, or there's something preventing them from reaching the Completed
state.
However, there is an example from Prefect recipes on GitHub, where an emit_event
is used to trigger an action when a flow run completes. Perhaps you could look into using events with your on_completion code to respond to completion instead of attempting to set the state directly.
Please check out the example to understand how to use emit_event
on completion:
Emit Event on Completion Example
Remember, for specific actions to enforce or change the state of a flow run, you'll need to interact with Prefect's API or use some of Prefect's state handling features. If the flow runs aren't completing as expected, you might need to investigate the reason for that. It could be due to tasks hanging, external services not responding, etc. Forcing a state change might mask underlying issues.Nate
03/04/2024, 3:13 AMon_completion
hook if you did not enter a Completed
state
there's likely something else going onNate
03/04/2024, 3:14 AMBlake
03/04/2024, 5:43 AMon_completion
hook is being called, yet the flow_run
param inside of the hook has a state still set to Running
.Nate
03/04/2024, 2:20 PMBlake
03/04/2024, 3:46 PMBlake
03/04/2024, 3:47 PMpersist_flow_run
hookNate
03/04/2024, 10:53 PMNate
03/04/2024, 10:55 PM