Parallel task definition object

Parallel task (identified by "type": "Parallel") causes parallel execution of "branches".

Here is an example:

"Lookup Customer Details": {
  "type": "Parallel",
  "branches": [
    {
      "startTask": "Lookup Address",
      "tasks": {
        "Lookup Address": {
          "type": "Http",
          "httpRequest": {
            "url": "https://nominatim.openstreetmap.org/search?addressdetails=1&format=json&q=Melbourne"
          },
          "end": true
        }
      }
    },
    {
      "startTask": "Lookup Phone Number",
      "tasks": {
        "Lookup Phone Number": {
          "type": "Http",
          "credentials": "CredentialsId",
          "httpRequest": {
            "url": "https://lookups.twilio.com/v2/PhoneNumbers/+15108675310?Fields=line_type_intelligence"
          },
          "end": true
        }
      }
    }
  ],
  "nextTask": "Next Task"
}

A Parallel task causes the system to execute each branch starting with the task named in its "startTask" field, as concurrently as possible, and wait until each branch terminates (reaches a terminal state) before processing the Parallel task's "nextTask" field.

In the above example, the system waits for "Lookup Address" and "Lookup Phone Number" to both finish before transitioning to "nextTask". The "Lookup Address" and "Lookup Phone Number" branches are executed in parallel.

A Parallel task MUST NOT be an End task.

The Parallel task has following additional fields:

Field

Type

Required

Description

branches

Array[JSON Object]

Yes

The array whose elements MUST be objects. Each object MUST contain fields named "tasks" and "startTask" whose meanings are exactly like those in the top level of a Workflow definition object.

Tasks in a branch's "tasks" field can transition only to each other, and no task outside of that "tasks" field can transition into it.

If any branch fails, the entire Parallel task is considered to have failed and all the branches are terminated. The system will terminate the workflow with an error.

A succeed task within a Parallel terminates its own branch. A succeed task passes its input through as its output.

nextTask

String

Yes

The next task to run, this is also called a joint task.

The Parallel task passes its input to each branch's "startTask" task. The output of Parallel task is the JSON Object of all branch outputs.

For example, consider the following Parallel task:

"Fun With Data": {
  "type": "Parallel",
  "branches": [
    {
      "startTask": "Now",
      "tasks": {
        "Now": {
          "end": true,
          "filter": ".",
          "inputParameters": {
            "now": "${jsonata:$now()}"
          },
          "type": "JQ"
        }
      }
    },
    {
      "startTask": "Random",
      "tasks": {
        "Random": {
          "end": true,
          "filter": ".",
          "inputParameters": {
            "random": "${jsonata:$random()}"
          },
          "type": "JQ"
        }
      }
    }
  ],
  "nextTask": "Combine Data"
}

The output of the Parallel task would be:

{
  "Now": {
    "result": {
      "now": "2023-08-03T14:24:13.763Z"
    },
    "resultList": [
      {
        "now": "2023-08-03T14:24:13.763Z"
      }
    ]
  },
  "Random": {
    "result": {
      "random": 0.35342521920876047
    },
    "resultList": [
      {
        "random": 0.35342521920876047
      }
    ]
  }
}