Hi everyone! Is there a good way to cancel a flow ...
# prefect-community
Hi everyone! Is there a good way to cancel a flow run using the REST API / prefect client with Prefect 2.0? Is this what the
flow run endpoint would be used for? https://docs.prefect.io/api-ref/rest-api/#/Flow%20Runs/set_flow_run_state_flow_runs__id__set_state_post
Hi Adam, yes, that is one way of changing the flow run's state to
. Here is an example of how to accomplish this through the Orion client as well.
As a fair warning though, the most effective way of cancelling a flow run would be cancelling the job in the infrastructure. (ex: by killing the process on that machine or the K8s job).
I'll drop a link to this previous thread here, as Michael described the nuances of cancellation very well there.
Thank you @Bianca Hoch! Canceling the infrastructure our flow is running (dataproc/spark) was another idea we had, although it seemed a bit more complex since cancellation would be happening in a web app context that is separate from our data pipelines. I saw this thread describe a way to handle state transitions such as cancellation from the prefect flow using the 1.0 SDK https://discourse.prefect.io/t/is-it-possible-to-take-action-on-flow-run-cancellation/141 Does Prefect 2.0 currently support a similar mechanism? Cancellation via stopping the underlying infrastructure seems like it could make it challenging to do hooks like this, i.e. posting to slack.
If Prefect 2.0 supported those state hooks, it seems like we could stop the dataproc cluster in there maybe.
Hello Adam, apologies for the delayed response. I've raised this to the team to see if we already have an equivalent way of handling this in 2.0, or if this is something we will have in our roadmap. 😄