Skip to content

Make scheduled flows not overlap in time #5373

Answered by anna-geller
igonro asked this question in Q&A
Discussion options

You must be logged in to vote

Here is an example state handler that allows you to skip (or cancel) a flow run if there are already some flow runs in progress. This allows non-overlapping flow runs, i.e. only one flow run of a specific flow at a time.

import prefect
from prefect import task, Flow
from prefect.client import Client
from prefect.engine.state import Skipped
import time


@task(log_stdout=True)
def hello_world():
    print("Sleeping...")
    time.sleep(360)


def skip_if_running_handler(obj, old_state, new_state):
    if new_state.is_running():
        client = Client()
        query = """
            query($flow_id: uuid) {
              flow_run(
                where: {_and: [{flow_id: {_eq: $flow_id}},

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@igonro
Comment options

Answer selected by igonro
Comment options

You must be logged in to vote
3 replies
@igonro
Comment options

@alexander-belikov
Comment options

@anna-geller
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants