Need help here. Trying to cancel the flow that is ...
# ask-community
s
Need help here. Trying to cancel the flow that is in running state, but getting the error. Step 1: Running flows and Step 2: Trying to cancel the flow. This is in prefect backend server
n
Hi @S K - you’ve input the flow ID instead of the flow run ID. In your initial query, grab the
id
field instead of the
flow_id
field
s
Thanks @nicholas that worked. Is it possible to cancel using the flow name?
n
No @S K, because the
cancel_flow_run
mutation is only tied to a specific run of a flow and not the flow itself; if we were to use the flow name, Prefect would either need to cancel all runs of that flow or make some assumption of your intent as to which run you wanted cancelled. This method is much more explicit.
s
@nicholas all I am trying is, if a flow name is already in running state, I don't want to trigger another run for the flow, since my schedule for the flow is every 15 minutes and so if the previous run is in progress, do not want to trigger the run
n
Got it - you'll want to query for the flow run something like this:
Copy code
query {
  flow( where: { name: { _eq: "<<your flow name>>" } } ) {
    flow_runs( where: { state: { _eq: "Running" } } ) {
      id   // use this id to cancel a flow run
    }
  }
}
upvote 1
👏 1