While loops
While loops execute a sequence of code until the user cancels, a step set to Early stop stops, or the loop reaches one of its iteration and duration limits.
How to stop a while loop
The loop will continue to run until canceled, there are 4 ways to stop a while loop:
- Cancel manually
- Early stop/Break for loop
- Early stop for step
- Limit iterations and duration
Cancel manually
You can cancel flow manually from the flow page, it can be accessed when the flow is triggered manually or from the Runs page.
Early stop / Break
The Early stop/Break feature allows you to define a predicate expression that determines whether the flow - or here, loop - should stop early at the end or before a step.
Early stop for step
For each step of the flow, an early stop can be defined. The result of the step will be compared to a previously defined predicate expression, and if the condition is met, the flow will stop after that step.
Limit iterations and duration
The Limit iterations and Limit duration toggles of the loop bound how long it can run (max_iterations and max_duration_secs in OpenFlow, both integers of at least 1).
The duration is wall-clock time since the first iteration started, so time spent waiting for a worker counts towards it.
Both limits are checked after each iteration, and a running iteration is never interrupted: a loop can exceed its maximum duration by up to one iteration. To cap a single iteration, set a timeout on the steps inside the loop.
When either limit is reached first, the loop fails with an error named LoopExhausted, unless the break condition stopped the loop at that same iteration.
If that iteration failed and Skip failure is off, the loop fails with the iteration's own error instead.
LoopExhausted is handled like any step failure: retries, the error handler, or Continue on error followed, as the very next step, by a branch on results.<loop_id>.error?.name === 'LoopExhausted'.
Skip failure
If set to true, the loop will continue to the next item even if the current item failed.
It does not apply to a loop reaching its limit, which still fails the loop.
Squash
If set to true, all iterations will be run on the same worker.
In addition, for supported languages (TypeScript and Python), a single runner per step will be used for the entire loop, eliminating cold starts between iterations.
We use the same logic as for Dedicated workers, but the worker is only "dedicated" to the flow steps for the duration of the loop.
Squashing cannot be used in combination with parallelization.
Test an iteration
You can get a test of the current iteration by clicking on the Test an iteration button.
Advanced settings
Early stop / Break
See above.
Suspend/Approval/Prompt
Flows can be suspended until resumed or canceled event(s) are received. This feature is most useful for implementing approval steps but can be used for other purposes as well.
Sleep
Executions within a flow can be suspended for a given time.
Mock
Step mocking / Pin result allows faster iteration while building flows. When a step is mocked, it will immediately return the mocked value without performing any computation, in test runs only or in every run.
Lifetime
The logs, arguments and results of this flow step will be completely deleted from Windmill once the flow is complete.