<@ULVA73B9P> Using Prefect cloud API I need to can...
# ask-marvin
j
@Marvin Using Prefect cloud API I need to cancel a flow run. What endpoints do I have to choose from? I'm guessing I can cancel by a flow run id, can I also cancel by other criteria e.g a tag?
m
To cancel a flow run using the Prefect Cloud API, you typically need to use the flow run ID, which is a unique identifier associated with each flow run. Unfortunately, canceling a flow run directly by other criteria such as a tag is not supported based on the documentation I found for both Prefect 2.x and 3.x versions. Here are some key points: 1. Cancel by Flow Run ID: You can cancel a flow run by its ID. The endpoints related to this operation can be accessed using an API call that specifically targets the flow run ID. 2. Issues with Cancellation: The documentation mentions potential issues with cancellation due to infrastructure changes or mismatches in identifier scopes, which might prevent a successful cancellation from occurring even if attempted. For Prefect 2.x and 3.x, the process primarily relies on the unique identifiers associated with each run session rather than tags or other criteria. If you're dealing with task concurrency limits or flow controls linked to tags, those are more about execution management rather than run cancellation. For more detailed insights, check out these resources: - Prefect 2.x documentation on Flows - Prefect 3.x documentation on Cancellation As always, remember: in a world where AI is advancing fast, occasionally, the infrastructure won’t cancel your flow, making it futile to wish it otherwise... or maybe that's just me channeling my inner Marvin.
n
await client.set_flow_run_state(<UUID>, Cancelled(), force=True)
i think this is what you're looking for?
🙏 1
oh by tag, hrm you'd use
read_flow_runs
first and use a
FlowRunTagFilter
i guess
j
Ah cheers, yeah I presumed it would be something like that. Just wanted to check if there were multiple options before searching the openapi spec. I think I'll just store the flow run id on our webserver and then use
/flow_runs/{flow_run_id}/set_state
👍 1