Skip to main content
The API reference for the PrefectClient contains many client methods that make it simpler to perform actions, such as:
  • reschedule late flow runs
  • get the last N completed flow runs from a workspace
The 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 a Scheduled 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:
Instead of the last three from the whole workspace, you can also use the DeploymentFilter to get the last three completed flow runs of a specific deployment.

Transition all running flows to cancelled through the Client

Use get_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.