Skip to main content

Wait for Step Completion

Use WaitForStepCompletion when a Flow has a durable client-visible milestone before its background work finishes. The caller starts the Flow, waits for that Step, then reads the result it needs. Later Steps can continue without holding the caller open.

The WaitForStepCompletionFlow sample persists a record in PersistData, then starts BackgroundWork. Its controller waits for PersistData before querying the persisted record. Choose a Step only after it has committed the state that makes the response valid.

Leave RequestTimeout at 0 for an ordinary durable wait. Set it explicitly at an admission boundary. The runnable controller below remains unbounded until its published SDK dependency includes this API. Each Flow allows a limited number of concurrent waits. See Choose the timeout boundary for details.

Core implementation​

@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