https://prefect.io logo
Title
k

Kirill Popov

11/17/2022, 3:21 PM
hi folks say if I want to delete ALL crashed flow runs or filter by some other condition & delete all flow runs how do I do it? now I am only able to get 200 flow runs in python… not even sure how does it decide which 200 setting up filters for flows in the query is virtual impossible for me (FlowRunFilter, FlowRunFilterState, …. a giant mess doesn’t work) please tell me I am doing it all wrong and there is an easy way? prefect 2 + prefect cloud
k

Kevin Wang

11/17/2022, 3:26 PM
Hi Kirill, you'd like to filter by some conditions.. you will need to use
FlowRunFilter
Try the below, you can see the commented params like limit, and sort.
state_filter = {}
state_filter["name"] = {"any_": ["Running"]}


flow_runs = asyncio.run(
    get_client().read_flow_runs(
        flow_run_filter=FlowRunFilter(state=state_filter) if state_filter else None,
        # limit=limit,
        # sort=FlowRunSort.EXPECTED_START_TIME_DESC,
    )
)
:gratitude-thank-you: 1
k

Kirill Popov

11/17/2022, 3:27 PM
why can i not increase the limit above 200?
k

Kevin Wang

11/17/2022, 3:28 PM
No idea.. Might be some behavior on Prefect Cloud side, but hope that helps you filter for your Crashed runs and you can delete them.
🙌 1
Since you are writing Python, I highly recommend cloning the
prefect
repo, which you can search through the code base. and see some tests written with them, as examples.
k

Kirill Popov

11/17/2022, 3:32 PM
@Kevin Wang thanks for the snippet, it worked too bad prefect cloud does not support retrieveing more than 200 flow runs at once similar in the UI — only some runs show up 😞
also kind of expected to be able to delete flow runs in the UI… multiselect with Shift and delete
a

Anna Geller

11/17/2022, 8:40 PM
you could leverage a for loop - it'S the same way as you would extract data from some API and responses would be paged
those limits are implemented for performance reasons, tradeoffs that we often have to make