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.

Dex derives the Request ID from the Step execution, so callers waiting for the same milestone share one accepted durable Update. Leave MaximumWaitTime at 0 for the normal infinite handler wait. A local HTTP or client deadline can still bound one response without cancelling that accepted handler. Set a positive value only when one Flow may accumulate abandoned or rarely completing Step waits. An expiry releases the in-flight slot, but continued waiting creates a new -N Update generation. See Choose the durable handler lifetime for the capacity and cost tradeoff.

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