Skip to main content

state

Syntax

Compact syntax:

- state:
- RESULT1: expression 1
- RESULT2: expression 2
- RESULT3: expression 3

Extended syntax:

- state:
- select: Result 1
when: expression
- select: Result 2
when: expression 2
- select: Result 3
when: expression 3

Description

A state operation is a control structure that allows a constant value to be assigned to a variable (or emitted to the next operation in the chain) based on testing a series of expressions. State is similar to an if/elseif/else statement in other programming languages.

State operations can have any number of result/expression pairs. When any variable or data source within any of the state's expressions changes, the entire state will be recalculated by evaluating each expression in the order they are provided. If an expression evaluates to true, the associated result will be captured and no further evaluation will occur. If an expression evaluates to false, the next expression in the list will be checked. If all expressions evaluate to false, then the result of the state operation will be the value passed into it from the previous operation in the chain, or UNAVAILABLE if it's the first operation.

Expressions within the state's rules can reference any other variable or data source within the config. If the state operation is NOT the first operation, then the special value this is also available for use, and holds the value passed in from the previous operation.

You should normally prefer the compact syntax for this operation. If you are trying to assign values that are more complex and might interfere with the YAML structure, then use the extended syntax instead.

Examples

  # Capturing a basic execution value
var1:
- state:
- ACTIVE: is-powered and is-cutting
- READY: true

# Overriding an execution value
var2:
- source: exec
- state:
- READY: this == "ACTIVE" and in-warmup-program
info

In the above example, is-powered, is-cutting, and exec are identifiers from another part of the program.