https://prefect.io logo
Title
a

Andreas

05/11/2023, 10:03 AM
Hello everyone! Does sb know if there is a on_cancelled hook that we can use for flows to execute code on cancellation (e.g like cleanup of things)?
v

Vadym Dytyniak

05/11/2023, 11:49 AM
+1
f

Filip Panovski

05/11/2023, 11:56 AM
There doesn't seem to be an
on_cancelled
hook, but you should be able to access the run state as described in this example: https://discourse.prefect.io/t/how-to-take-action-on-a-state-change-of-a-task-run-task-level-state-handler/82 It seems that this only applis to tasks though, not flows. Perhaps it might work if you submit your flow as a subflow and access the future from the parent flow.
You can also return the flow state directly using `return_state=True`: https://docs.prefect.io/latest/concepts/states/#return-prefect-state
d

Deceivious

05/11/2023, 12:41 PM
Note
on_cancelled
si coming soon? 😄 i think i remember reading it somewhere
f

Filip Panovski

05/12/2023, 4:42 PM
@Deceivious Probably thinking of https://github.com/PrefectHQ/prefect/pull/9389 🙂
s

Serina

05/25/2023, 10:00 PM
The
on_cancellation
flow run state change hook is released. Please see our new documentation for more details: https://docs.prefect.io/latest/concepts/states/#state-change-hooks
🙌 1