Skip to main content
Version: Current

While

Mode: Streaming Mode: Request-Response

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​

NameDescription
ConditionChecked each time a record comes in, on entry and on return. A condition that is null does not hold.
Max iterationsHow 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​

NameDescription
bodyThe condition holds.
doneThe condition does not hold, so the loop ends.
on errorThe 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 While keeps its value between rounds. Change it with a Variable node whose Operation, under Advanced, is Overwrite.
  • A variable declared in the body lasts until the record returns to While. To keep its value, overwrite a variable declared before While with it.
  • After done only the variables declared before While are 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 iterations times fails, going to on error where it is connected. A nested While counts from each entry.
  • on error cannot lead back to its own While, but it can lead back to a While the loop is nested in.
  • However While is 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 Split can 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 the timeout in the part of the scenario holding the loop.