While
Description
While sends a record round a loop drawn on the graph, as long as its condition holds.
Use it for a retry, for polling or for any step repeated a number of times not known up front.
Variable i = 0 → While #i < 3 ─ body → ... → Variable i = #i + 1 (Overwrite) ─┐
▲ │
└──────────────────────────────────────────────────────────┘
While ─ done → sink
Parameters and configuration
| Name | Description |
|---|---|
| Condition | Checked each time a record comes in, on entry and on return. A condition that is null does not hold. |
| Max iterations | How many times at most the body runs for one record, 10 by default and up to 1000. A record whose condition still holds after that fails. |
Outputs
| Name | Description |
|---|---|
| body | The condition holds. |
| done | The condition does not hold, so the loop ends. |
| on error | The record failed in While: its condition could not be evaluated, or the body would run more than Max iterations times. The record keeps the variables it had, and #error holds the message and nodeId of the failure. Without it, the record ends in an error. |
How variables behave in a loop
- A variable declared before
Whilekeeps its value between rounds. Change it with aVariablenode whoseOperation, underAdvanced, isOverwrite. - A variable declared in the body lasts until the record returns to
While. To keep its value, overwrite a variable declared beforeWhilewith it. - After
doneonly the variables declared beforeWhileare available, with their last values.
Giving a variable a new value
A Variable node with Operation set to Overwrite gives a variable already in scope a new value. Global variables, such as #meta, cannot be overwritten.
The variable keeps its type, so one declared as a number cannot become text.
A value of a narrower type is widened, e.g. an Integer given to a Long variable, while a wider one has to be converted in the expression, e.g. with toInteger, also in the fields of a record.
A variable declared as null has no known type, so it takes any value, but its fields cannot be read in an expression without converting it first.
Limits
- The path back has to stay in one part of the scenario, so it cannot go through an aggregate, a join, For Each or another stateful component. Put those before the loop or on a path leaving it.
- A record whose body would run more than
Max iterationstimes fails, going toon errorwhere it is connected. A nestedWhilecounts from each entry. on errorcannot lead back to its ownWhile, but it can lead back to aWhilethe loop is nested in.- However
Whileis set up, a record that would come back to a loop node more than 1000 times, or go round the loops of one part of the scenario more than 10000 times in total, fails the same way, so an endless loop cannot hang a task. - Only one path of a
Splitcan lead back. - On Flink, a loop that calls services, such as enrichers, has to finish all rounds of a record within the model's
timeout. A record that does not make it ends in an error, rather than stopping the scenario as a timeout elsewhere does; so does any record running out of thetimeoutin the part of the scenario holding the loop.