Skip to content

Instantly share code, notes, and snippets.

@Ogaday
Created October 2, 2023 07:52
Show Gist options
  • Save Ogaday/c698574d8a19af1d4e27355c3c2e1cbc to your computer and use it in GitHub Desktop.
Save Ogaday/c698574d8a19af1d4e27355c3c2e1cbc to your computer and use it in GitHub Desktop.
Delete flow runs
# In IPython:
from prefect.client.orchestration import get_client
from prefect.server.schemas.filters import FlowRunFilter, FlowRunFilterState, FlowRunFilterStateName, FlowRunFilterStartTime, FlowFilterName, FlowFilter, FlowFilterId
async with get_client() as client:
flow = await client.read_flow_by_name("flow-name")
async with get_client() as client:
flow_runs = await client.read_flow_runs(
flow_filter=FlowFilter(id=FlowFilterId(any_=[flow.id])),
flow_run_filter=FlowRunFilter(
state=FlowRunFilterState(
name=FlowRunFilterStateName(any_=["Pending", "Running"])
)
)
)
async with get_client() as client:
for fr in flow_runs:
print(fr.name)
ret = await client.set_flow_run_state(flow_run_id=fr.id, state=State(type="CANCELLED"))
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment