Hi team, is there an API that I can use to get bot...
# prefect-cloud
h
Hi team, is there an API that I can use to get both scheduled and running flow runs given a deployment id? I only found
.../deployments/get_scheduled_flow_runs
n
hi @Hristo Papazov - you can use the
read_flow_runs
client method (or the endpoint it is using,
POST /flow_runs/filter
) like this
Copy code
In [1]: from prefect import get_client

In [2]: from prefect.client.schemas.filters import FlowRunFilter

In [3]: async with get_client() as client:
   ...:     runs = await client.read_flow_runs(
   ...:         flow_run_filter=FlowRunFilter(
   ...:             state=dict(name=dict(any_=["Failed", "Crashed"])),
   ...:             deployment_id=dict(any_=["d17fe4e4-382a-4d34-9a8d-c6a39407103c"])
   ...:         )
   ...:     )
   ...:

In [4]: len(runs)
Out[4]: 3

In [5]: assert all(run.state.name in ("Failed", "Crashed") for run in runs)
more examples here
h
Thanks @Nate! I think I can use
POST /flow_runs/filter-minimal
. I also need to get work queue/pool concurrency limits and looks like the response contains that information. In the API documentation for Read Flow Runs Minimal I see this note
A flow runs filter that excludes full state data -- and possibly other data in the future -- for improved performance.
Do you know if work_queue and work_pool data could be excluded in the future?