Parallel state allows you to process multiple states in parallel and perform simultaneous executions.
The executions are initiated at the same time, and their input, output, and results are processed and generated concurrently. Additionally, the states exit only when all parallel tasks execution is completed. You can check the parallel processing from the execution logs after the Circuit has been executed.
Example Use Case: In the employee onboarding scenario, once the employee documents have been verified, we can add a state to provision the verified employees within the organization. Provisioning involves executing multiple tasks in parallel, such as adding user details in Active Directory, adding the user to the team's channel, making an entry in the legacy database, and allocating resources. This parallel execution of tasks can be accomplished using the Parallel state, allowing all four tasks to be performed simultaneously.
Let us see how to configure the Parallel state in Builder View and Code View.
Builder View
To execute states in parallel, you must configure them as paths in the Parallel state.
In Builder View, drag and drop the Parallel state from the left pane into your circuit or click the required Parallel state in your circuit.
Under the Configurations tab, update the common state field attributes.
In the Path section, click Add Path to insert a state that will serve as the root or starting point for the path. Once the state is added, provide a name for the path in the designated Name field.
In the Input/Output section, you can configure the required paths for a parallel state as discussed in Input & output processing.
If any path fails, either by an unhandled error or by transitioning to a failure state, the entire Parallel state is considered failed, halting all paths. If the error is not handled by the Parallel state itself, the circuit terminates the execution with an error.
The parallel state can only be deleted if all its sub-states have been deleted.
It is not possible to configure a parallel state within another parallel state.
Code View
In Code View, along with the common fields, the paths are also defined with their unique name and root.
Parallel state example:
"Parallel IT Tasks - Employee Provisioning": {
"type": "parallel",
"next": "Onboarded Successfully",
"paths": [
{
"name": "add_ad_user",
"root": "Add User in AD"
},
{
"name": "add_ad_group",
"root": "Add User to AD Group"
},
{
"name": "add_user_db",
"root": "Add User in Legacy Database"
},
{
"name": "add_asset",
"root": "Asset Allocation"
}
]
}