All Products
Search
Document Center

CloudFlow:Inline mode

Last Updated:Nov 26, 2024

By default, Map states run in inline mode. The inline mode can be used to batch-process data and streamline data transformation and processing. The mode focuses on a single node and is suitable for scenarios in which each element in a collection requires processing.

Overview

A Map state is used to traverse a parameter of the array type in the input and execute the Processor states in parallel for all elements in the array. A Map state is similar to the foreach statement in programming languages. However, the iterations in Map are executed in parallel.

When a Map state is executed, the Processor states of all elements in the input parameter are concurrently executed. By default, a map[string]any output that contains the results of all branches is returned after all branches are executed. Then, the system uses the output constructor to further process the results.

The following table describes the fields in the inline mode.

Field

Type

Required

Description

Example

Name

string

Yes

The name of the state.

my-state-name

Description

string

No

The description of the state.

describe it here

Type

string

Yes

The type of the state.

Map

InputConstructor

map[string]any

No

The input constructor.

See Inputs and outputs.

ItemsPath

string

Yes

The expression that is used to extract an array within an input.

See ItemsPath.

Processor

Processor

Yes

The iteration processor.

See Processor.

OutputConstructor

map[string]any

No

The output constructor.

See State OutputConstructor.

Next

string

No

The next state that is executed after the current state is complete. If the value of the End field is true, you do not need to specify this field.

my-next-state

End

bool

No

Specifies whether the state is the terminal state of the current scope.

true

Retry

Retry

No

The error retry policy.

See Error handling.

Catch

Catch

No

The error catch policy.

See Error handling.

MaxConcuccency

int

No

The maximum concurrency level.

28

Important fields for the inline mode

ItemsPath

The expression that is used to extract an array within an input. If a JSON array is returned after an ItemsPath expression is executed, the array is iterated over. Each element in the array is passed to ItemProcessor for processing. You can use the $Context and $Input expression variables, as shown in the following example:

$Input.FieldA

Processor

The iteration processor. The field contains two fields described in the following table.

Field

Type

Required

Description

Example

States

array

Yes

The array of states.

Processor:
   StartAt: Pass1
   States:
     - Type: Pass
       Name: Pass1
       End: true

StartAt

string

Yes

The state from which the execution of the workflow starts.

my start task

MaxConcuccency

The maximum number of concurrent sub-flows. The maximum value of this field is 40.

Sample code

The following sample flow defines a Map state. The MapProcessor contains a Pass state.

Type: StateMachine
Name: my-wkfl
SpecVersion: v1
StartAt: Map1
States:
  - Type: Map
    Name: Map1
    End: true
    InputConstructor:
      FieldA: 
        - a : b
        - c : d
        - e : f
    ItemsPath: $Input.FieldA
    Processor:
      StartAt: Pass1
      States:
        - Type: Pass
          Name: Pass1
          End: true

The following sample code provides an example of the input construction result of the flow.

{
    "FieldA": [
        {
            "a": "b"
        },
        {
            "c": "d"
        },
        {
            "e": "f"
        }
    ]
}

For a Map, the system merges the outputs of all iteration processors. By default, the Items keyword is used as the key and the merged result is used as the value. The following sample code provides an example of the output of Map1. This is also the final output after the flow is executed.

{
    "Items": [
        {
            "a": "b"
        },
        {
            "c": "d"
        },
        {
            "e": "f"
        }
    ]
}