Skip to main content

Wait for Step Completion

View as Markdown

WaitForStepCompletion returns once one Step execution of a running Flow has completed. Use it when a Flow reaches a durable point that the caller can use before the background work finishes.

How it works

The caller starts the Flow, waits for that Step execution, then reads the result it needs. The caller does not wait for later Steps.

In the example, PersistData saves a record, then starts the background Step. The controller waits for the first PersistData execution. Then it reads the saved record through an RPC, except in Rust, which returns only the Flow ID and run ID.

Core implementation

The controller starts the Flow, waits for PersistData, and reads the record.

controller.pyPython
@blueprint.get("/start")
async def start_wait_for_step_completion() -> str:
flow_id = required_query("workflowId")
await app_state.client.start_flow(
app_state.wait_for_step_completion,
flow_id,
JobSeekerData(1),
start_options(),
)
await app_state.client.wait_for_step_completion(
flow_id,
PERSIST_DATA_STEP,
WaitForStepCompletionOptions(),
)
persisted = await app_state.client.invoke_rpc(
app_state.wait_for_step_completion.get_job_seeker_data,
flow_id,
)
payload = json.dumps(asdict(persisted), sort_keys=True)
return f"success for workflow {flow_id} with data {payload}"

Example: examples/python/dex_examples/patterns/wait-for-step-completion/controller.py

Rules and pitfalls

  • Wait for the Step that saved the state. Choose a Step that completes only after it has saved the state the response needs.
  • Read the result separately. The wait confirms completion and returns no Step output. Read the state through an RPC or a Client Attribute read.
  • Set a request timeout behind a deadline. When the wait runs behind an HTTP endpoint or another entry point with its own deadline, set RequestTimeout. The runnable controllers leave it unset; the Go controller bounds the call with a five-minute context. See Wait timeouts and limits.

Next