Mixed Flow
Overview
Mixed flow
allows execution of other flows (child flows) within the flow (parent). The execution can be done in parallel (asynchronously) or sequentially (synchronously).
This is useful when there is common logic that is shared among multiple flows (e.g. jwt validation, re-mapping of doc
nodes) and allows to separate this logic into a child flow that then can be called from the parent.
Configuration
mode
- this option allows the user to specify how the flow configuration data should be passed to the step.flow (default)
- straightforward ui to fill the necessary inputs:list of flows to execute
- one or more flows that can be selected for execution (note: in case of synchronous execution the order of the flows is important)flow name
- the name of the flow to execute;payload path (defaults to doc)
- path to the payload of data to send to the flow;target path
- where to store the result of the executed flow;Store target path results in cache
- if checked will enable caching response valuesCache Key
- if specified, will be used as key to store the cached responseCache clean-up condition
- If condition is true, then step cache is cleared, else if condition is false or not defined, then step behaves as usually.TTL
- time in minutes for how long to keep the cached resultsprocess data as array
- when checked, allows the user to pass data to the flow as an array of data objects.concurrency
- in case of async execution - this sets the maximum amount of flows to execute at a single time This will result in a loop of flow executions with these data objects being passed in each iteration;
bind
- this option changes how one would pass the configuration data to the step. The path of this input should result in an array of objects containing the following structure of previously described data:
Execute flows in parallel
- Default is false, which means flows will be executed in serial. If set to true, the all flows will be executed in parallel.Execute flows in background
- Default is false. If set to true, the mixed flow step will execute flows in background and won't wait till it's finished before returning response.
The flows executed in background will not modify the doc
object of main/parent flow.
{
"flows": [
{
"flowId": "myFlow",
"payload": "data.toSend",
"targetPath": "result",
"processAsArray": false,
"cacheable": false,
"ttl": 0
}
]
}
Caching
Mixed flow step supports flow execution result caching. Result caching happens based on flow input data. Because of this it is advised to use payload path to specify only part of doc needed to execute flow.
Examples
These examples use flow exampleSubFlow
tags:
- example
steps:
- stepType: code
config:
codeBlock: number * 2
targetPath: number
condition: "{{number}}"
name: JS Code Functions
description: ""
sampleData: {}
Synchronous execution
Execute flow one by one in serial.
Step configuration:
stepType: mixedflow
config:
mode: flow
async: false
flowIds:
- flowId: exampleSubFlow
- flowId: exampleSubFlow
concurrency: 0
name: Mixed-flow
description: ""
condition: ""
Input data:
{
"number": 16
}
Result:
{
"doc": {
"number": 64
},
"errors": [],
"performance": {
"steps": [
{
"step": "mixedflow",
"executionTime": 57
}
],
"executionTimeOfFlow": 57,
"timeMetric": "ms"
}
}
Complete flow:
tags:
- example
steps:
- stepType: mixedflow
config:
mode: flow
async: false
flowIds:
- flowId: exampleSubFlow
- flowId: exampleSubFlow
concurrency: 0
name: Mixed-flow
description: ""
condition: ""
sampleData:
number: 16
Asynchronous execution
The only difference between this and previous flow is that we have changed the execution mode to async
and set the limit of parallel flows to execute to 2.
Step configuration
stepType: mixedflow
config:
mode: flow
async: true
flowIds:
- flowId: exampleSubFlow
- flowId: exampleSubFlow
concurrency: 2
name: Mixed-flow
description: ""
condition: ""
Input data:
{
"number": 16
}
Result:
Since the flows are executed in parallel, both receive the starting input - so the result is that the input number gets multiplied by 2 instead of 16 * 2 * 2
because in essence both flows receive the same input number: 16
and then at the end of run both flows set the number to 32.
{
"doc": {
"loopResult": 32
},
"errors": [],
"performance": {
"steps": [
{
"step": "mixedflow",
"executionTime": 52
}
],
"executionTimeOfFlow": 52,
"timeMetric": "ms"
}
}
Complete flow:
tags:
- example
steps:
- stepType: mixedflow
config:
mode: flow
async: true
flowIds:
- flowId: exampleSubFlow
- flowId: exampleSubFlow
concurrency: 2
name: Mixed-flow
description: ""
condition: ""
sampleData:
loopResult: 16
Process data as array
This example processes data as array. It can be useful to iterate through result list.
Step configuration:
- name: Step mixedflow
description: ""
config:
mode: flow
async: false
isBackground: false
flowIds:
- processAsArray: true
flowId: subflow.yaml
payload: input
targetPath: mixed-flow-output
stepType: mixedflow
condition: ""
subflow
which is executed for every array item:
tags: []
sampleInputSchema: ""
sampleData: {}
description: ""
steps:
- name: Step jsonata
description: ""
config:
maps:
- jsonata: '{"subflow-input": $}'
targetPath: output
stepType: jsonata
condition: ""
resultPath: output
Input data
{
"input": [
{
"data": "value1"
},
{
"data": "value2"
}
]
}
Output data:
For every array item subflow
is executed and result is stored in mixed-flow-output
array.
{
"doc": {
"input": [
{
"data": "value1"
},
{
"data": "value2"
}
],
"mixed-flow-output": [
{
"subflow-input": {
"data": "value1"
}
},
{
"subflow-input": {
"data": "value2"
}
}
]
}
}
Complete flow:
tags: []
sampleInputSchema: ""
sampleData:
input:
- data: value1
- data: value2
description: ""
steps:
- name: Step mixedflow
description: ""
config:
mode: flow
async: false
isBackground: false
flowIds:
- processAsArray: true
flowId: subflow.yaml
payload: input
targetPath: mixed-flow-output
stepType: mixedflow
condition: ""