Hello everyone! Does sb know if there is a on_canc...
# ask-community
a
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
+1
f
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
Note
on_cancelled
si coming soon? 😄 i think i remember reading it somewhere
f
@Deceivious Probably thinking of https://github.com/PrefectHQ/prefect/pull/9389 🙂
s
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