Pause or suspend a flow run
Prefect allows you to halt a flow run with two functions that are similar, but slightly different. When a flow run is paused, code execution is stopped and the process continues to run. When a flow run is suspended, code execution is stopped and so is the process.Pause a flow run
Prefect enables pausing an in-progress flow run for manual approval. Prefect exposes this functionality with thepause_flow_run
and resume_flow_run
functions.
TimeoutsPaused flow runs time out after one hour by default.
After the timeout, the flow run fails with a message saying it paused and never resumed.
Specify a different timeout period in seconds using the
timeout
parameter.pause_flow_run
inside a flow:
resume_flow_run
utility through client code.
Suspend a flow run
Similar to pausing a flow run, Prefect enables suspending an in-progress flow run.The difference between pausing and suspending a flow runThere is an important difference between pausing and suspending a flow run.
When you pause a flow run, the flow code is still running but is blocked until someone resumes the flow.
This is not the case with suspending a flow run.
When you suspend a flow run, the flow exits completely and the infrastructure running it (for example, a Kubernetes Job) tears down.
suspend_flow_run
and
resume_flow_run
functions, as well as the Prefect UI.
When called inside of a flow, suspend_flow_run
immediately suspends execution of the flow run.
The flow run is marked as Suspended
and will not resume until resume_flow_run
is called.
TimeoutsSuspended flow runs time out after one hour by default.
After the timeout, the flow run fails with a message saying it suspended and never resumed.
You can specify a different timeout period in seconds using the
timeout
parameter or pass timeout=None
for no timeout.suspend_flow_run(flow_run_id=<ID>)
or
selecting the Suspend button in the Prefect UI or Prefect Cloud.
Resume suspended flow runs can by clicking Resume in the Prefect UI or calling the resume_flow_run
utility through client code.
You can’t suspend subflows independently of their parent runIf you use a flow to schedule a flow run with
run_deployment
, the
scheduled flow run is linked to the calling flow as a subflow run by
default. This means you can’t suspend the scheduled flow run
independently of the calling flow.Call run_deployment
with
as_subflow=False
to disable this linking if you need to suspend
the scheduled flow run independently of the calling flow.Waiting for input when pausing or suspending a flow run
ExperimentalThe
wait_for_input
parameter used in the pause_flow_run
or suspend_flow_run
functions is an experimental feature.
The interface or behavior of this feature may change without warning in future releases.If you encounter any issues, please let us know in Slack or with a GitHub issue.pause_flow_run
and suspend_flow_run
functions.
These functions accept a wait_for_input
argument, which should be a subclass of prefect.input.RunInput
(a Pydantic model).
When resuming the flow run, users are required to provide data for this model. After successful validation,
the flow run resumes, and the return value of the pause_flow_run
or suspend_flow_run
is an instance of the model containing the provided data.
Here is an example of a flow that pauses and waits for input from a user:
pause_flow_run
,
at which point it moves into a Paused
state.
Execution blocks and waits for resumption.
When resuming the flow run, users are prompted to provide a value for the name
field of the UserNameInput
model.
After successful validation, the flow run resumes, and the return value of the pause_flow_run
is an instance of the UserNameInput
model containing the provided data.
For more information on receiving input from users when pausing and suspending flow runs,
see Create interactive workflows.