https://prefect.io logo
Title
a

Ankit

01/30/2023, 8:53 AM
Hi, I created a new deployment with schedule set to run the flow every 5 minutes. At certain times of the day, my flow takes more than 5 mins and I would want to cancel the flow run if the previous flow is still running. Is there a direct way of doing that or I should be using APIs to get the count of running flows and add that as a condition in my flow?
r

redsquare

01/30/2023, 9:04 AM
You could use task concurrency and set it to one
a

Ankit

01/30/2023, 9:05 AM
but I would want to run tasks of that flow concurrently, just have to avoid flows running in parallel
r

redsquare

01/30/2023, 9:07 AM
It can be set against a work queue too
Flow run concurrency on the queue
a

Ankit

01/30/2023, 9:12 AM
that's right. only problem is that the next flow stays in late stage, I wanted that to be cancelled so that it doesn't keep too many flows in late stage if say the current run goes on for over 15 mins that would add 3 in late stage
r

redsquare

01/30/2023, 9:13 AM
Why not schedule the next run on completion then instead of having a schedule?
a

Ankit

01/30/2023, 9:14 AM
yes, can do that too. every flow ends with scheduling a new run, that's what you mean right?
r

redsquare

01/30/2023, 9:14 AM
yup
a

Ankit

01/30/2023, 9:14 AM
should work for most use cases, will try that. Thanks 😄
👍 1
only one problem, if any flow fails then the next run won't get scheduled. Trying with the APIs
r

redsquare

01/30/2023, 9:38 AM
You could use retries for that - but yeah you might need a flow to check last run time and kick off the flow if it hasnt run for a bunch of time
a

Ankit

01/30/2023, 9:38 AM
right or schedule the next flow irrespective of flow failing or succeeding
used API to check if the last flow is already running and then cancelling the new one