https://prefect.io logo
m

Mitchell Bregman

09/06/2023, 7:49 PM
using the Prefect python SDK, how can I query all flow runs under a certain deployment id?
1
Copy code
res = await client.read_flow_runs(deployment_filter={"DeploymentID": "2d73c29e-5865-44d4-8f4e-4e3d9dc0442c"})
results in:
Copy code
AttributeError: 'dict' object has no attribute 'dict'
are there docs associated to the
DeploymentFilter
object?
j

Jake Kaplan

09/06/2023, 7:56 PM
Hey, I think you're looking for something like this:
Copy code
import asyncio
from prefect.client.orchestration import get_client
from prefect.client.schemas.filters import DeploymentFilter, DeploymentFilterId
from uuid import UUID


async def read_flows_for_deployment(deployment_id: UUID):
    async with get_client() as client:
        flow_runs = await client.read_flow_runs(
            deployment_filter=DeploymentFilter(
                id=DeploymentFilterId(any_=[deployment_id])
            )
        )
        for r in flow_runs:
            print(r.id)


if __name__ == '__main__':
    asyncio.run(read_flows_for_deployment(UUID("d6f41eb0-bbef-4d9e-b84d-aad77deb396b")))
m

Mitchell Bregman

09/06/2023, 8:14 PM
thank you @Jake Kaplan - and to stop/cancel a flow run via sdk? i tried deleting but im still seeing k8 pods recreating
Copy code
await client.set_flow_run_state(r.id, Cancelled(), True)
?
cancelling is the graceful way to shut down. deleting the flow run kind of just pulls the plug, something will hit a wall eventually if the flow run suddenly disappears
1