KG
02/27/2024, 9:49 PMraise UnfinishedRun(
prefect.exceptions.UnfinishedRun: Run is in PENDING state, its result is not available.)
Is this intended? Is there another way of cancelling or deleting Pending flowruns without using the UIJake Kaplan
02/27/2024, 10:18 PMJake Kaplan
02/27/2024, 10:33 PMPENDING
stateJake Kaplan
02/27/2024, 10:33 PMimport asyncio
from prefect import get_client
from prefect.client.schemas.filters import FlowRunFilter, FlowRunFilterState, FlowRunFilterStateType
from prefect.states import StateType
async def delete_flow_runs():
async with get_client() as client:
limit = 50
while True:
flow_runs = await client.read_flow_runs(
limit=limit,
flow_run_filter=FlowRunFilter(
state=FlowRunFilterState(
type=FlowRunFilterStateType(
any_=[StateType.PENDING]
)
)
)
)
print(f"Deleting {len(flow_runs)} flow runs")
if not flow_runs:
break
for flow_run in flow_runs:
print(f"Deleting flow run {flow_run.id}")
await client.delete_flow_run(flow_run.id)
if __name__ == '__main__':
asyncio.run(delete_flow_runs())
KG
02/28/2024, 1:07 AM