<@ULVA73B9P> can I create an automation in prefect...
# ask-marvin
a
@Marvin can I create an automation in prefect cloud which check if another flow from the same deployment is running and cancels the run to ensure only one flow run from a deployment?
m
To ensure only one flow run from a deployment is running at a time in Prefect Cloud, you can use the concurrency settings of work pools. Each work pool can restrict concurrent runs of matching flows, which allows you to set a concurrency limit. For example, if you set a concurrency limit to 1 for a work pool that is tied to a specific deployment, it will only allow one flow run to be active at a time. If a run is already in a
Running
or
Pending
state, polling the pool for work will not allow additional runs to start until the existing ones have finished. Here is the excerpt from the Prefect documentation about managing concurrency with work pools: "Each work pool can optionally restrict concurrent runs of matching flows. For example, a work pool with a concurrency limit of 5 will only release new work if fewer than 5 matching runs are currently in a
Running
or
Pending
state. If 3 runs are
Running
or
Pending
, polling the pool for work will only result in 2 new." Manage concurrency with work pools However, this does not include functionality for canceling ongoing runs if a new run is attempted. Fully automated cancellation based on new runs would require custom logic, potentially through state handlers, listeners, or an orchestration process that uses the Prefect API to monitor and cancel runs. As of my knowledge cutoff in April 2023, Prefect Cloud does not seem to provide built-in features to cancel an ongoing flow run when a new run from the same deployment is attempted.