This topic describes parallel steps and related examples.
Overview
A parallel step is used to execute multiple child steps in parallel. A parallel step defines multiple branches, each of which contains a series of serial steps.
Each branch of a parallel step corresponds to a local variable. When a parallel step is executed, serial steps in all branches are executed concurrently. These serial steps change the local variables corresponding to their branches. After all branches are executed, output mappings can be used to convert the local variable arrays of branches into the output of the parallel step.
A parallel step contains the following attributes:
- type: Required. The step type. The value parallel indicates that the step is a parallel step.
- name: Required. The step name.
- branches: Required. Multiple branches of the array type. Each element corresponds to a branch.
- steps: Required. The multiple serial steps defined for a branch.
- end: Optional. Specifies whether to proceed with the subsequent steps after the current step ends.
- inputMappings: Optional. The input mappings.
- outputMappings: Optional. The output mappings. In this step, the
$local
is an array. Each element in the array is a JSON object that records the execution result of each branch.Note If no output mappings are specified, this step has no output by default.
Examples
The following sample flow defines a parallel step. This parallel step contains two branches, and each branch contains a pass step.
version: v1
type: flow
steps:
- type: parallel
name: myparallel
branches:
- steps:
- type: pass
name: pass1
outputMappings:
- target: result
source: pass1
- steps:
- type: pass
name: pass2
outputMappings:
- target: result
source: pass2
outputMappings:
- target: result
source: $local[*].result
- The following information is the output of
pass1
:{ "result": "pass1" }
- The following information is the output of
pass2
:{ "result": "pass2" }
- The following information is the output of
myparallel
:{ "result": ["pass1", "pass2"] }