<@ULVA73B9P> using prefect3, rest api. outside of ...
# ask-marvin
d
@Marvin using prefect3, rest api. outside of polling logs, how do i poll the state of a scheduled flow run after using deployment/create_flow_run?
m
To poll the state of a scheduled flow run in Prefect 3.x after using
deployment/create_flow_run
, you can use the
wait_for_flow_run
function from the
prefect.flow_runs
module. This function allows you to wait for a flow run to complete and can be configured with a timeout and polling interval. Here's a brief overview:
Copy code
python
from prefect.flow_runs import wait_for_flow_run
from uuid import UUID

async def check_flow_run_state(flow_run_id: UUID):
    flow_run = await wait_for_flow_run(
        flow_run_id=flow_run_id,
        timeout=10800,  # Optional: specify how long to wait (in seconds)
        poll_interval=5,  # Optional: specify how frequently to poll (in seconds)
        log_states=True  # Optional: log state transitions
    )
    return flow_run.state
This function will return the final state of the flow run after it completes or times out. You can adjust the
timeout
and
poll_interval
parameters to suit your needs. For more details, you can refer to the flow_runs.py source code where this function is defined. If you prefer to use the Prefect REST API directly, you would need to periodically query the API for the flow run's state using its ID.