PrefectClient
contains many client methods that make it simpler to perform actions, such as:
- reschedule late flow runs
- get the last
Ncompleted flow runs from a workspace
PrefectClient is an async context manager. Here’s an example usage:
Examples
Reschedule late flow runs
To bulk reschedule flow runs that are late, delete the late flow runs and create new ones in aScheduled state with a delay. This is useful if you accidentally scheduled many
flow runs of a deployment to an inactive work pool, for example.
The following example reschedules the last three late flow runs of a deployment named
healthcheck-storage-test to run six hours later than their original expected start time.
It also deletes any remaining late flow runs of that deployment.
Get the last N completed flow runs from your workspace
To get the last N completed flow runs from your workspace, use read_flow_runs and prefect.client.schemas.
This example gets the last three completed flow runs from your workspace:
DeploymentFilter
to get the last three completed flow runs of a specific deployment.
Transition all running flows to cancelled through the Client
Useget_clientto set multiple runs to a Cancelled state.
The code below cancels all flow runs that are in Pending, Running, Scheduled, or Late states when the script is run.