Pause

Suspend a workflow at a named point and resume it later.

Suspends a workflow mid-run and resumes it on a later call. The pause built-in stops execution at a named checkpoint; the workflow stays in a paused state until it is run again with the same execution_id. Reach for this when a workflow must wait for an external signal — an approval, a manual review, a downstream job.

Run it

python examples/pause.py
from __future__ import annotations

from datetime import timedelta

from flux import ExecutionContext
from flux.task import task
from flux.tasks import pause
from flux.tasks import sleep
from flux.workflow import workflow


@task
async def proces_data():
    # Simulate some data processing
    await sleep(timedelta(seconds=2))
    return "Data processed"


@workflow
async def pause_workflow(ctx: ExecutionContext):
    result = await proces_data()
    await pause("wait_for_approval")
    return result + " and approved"


if __name__ == "__main__":  # pragma: no cover
    ctx = pause_workflow.run()
    ctx = pause_workflow.run(execution_id=ctx.execution_id)
    print(ctx.to_json())

Walk-through

  1. The first pause_workflow.run() executes proces_data, hits pause("wait_for_approval"), and returns a paused ExecutionContext.
  2. The second run(execution_id=ctx.execution_id) resumes the same execution. proces_data is not re-run — its recorded result is replayed — and the workflow continues past the pause to return the final value.
  3. The pause name ("wait_for_approval") identifies the checkpoint, which matters once a workflow has more than one pause point.

See also


Last verified against Flux 0.56.0.