EachParallel EachParallel

yaml
type: "io.kestra.core.tasks.flows.EachParallel"

For each value in the list, execute one or more tasks in parallel.

The list of tasks will be executed for each item in parallel. The value must be a valid JSON string representing an array, e.g. a list of strings ["value1", "value2"] or a list of dictionaries [{"key": "value1"}, {"key": "value2"}]. You can access the current iteration value using the variable .

The task list will be executed in parallel for each item. For example, if you have a list with 3 elements and 2 tasks defined in the list of tasks, all 6 tasks will be computed in parallel without any order guarantee.

If you want to execute a group of sequential tasks for each value in parallel, you can wrap the list of tasks with the Sequential task. If your list of values is large, you can limit the number of concurrent tasks using the concurrent property.

We highly recommend triggering a subflow for each value (e.g. using the ForEachItem task) instead of specifying many tasks wrapped in a Sequential task. This allows better scalability and modularity. Check the flow best practices documentation for more details.

Examples

yaml
id: each-parallel
namespace: io.kestra.tests

tasks:
  - id: each-parallel
    type: io.kestra.core.tasks.flows.EachParallel
    value: '["value 1", "value 2", "value 3"]'
    tasks:
      - id: each-value
        type: io.kestra.core.tasks.debugs.Return
        format: "{{ task.id }} with current value '{{ taskrun.value }}'"
yaml
id: each-parallel
namespace: io.kestra.tests

tasks:
  - id: each-parallel
    type: io.kestra.core.tasks.flows.EachParallel
    value: 
      - value 1
      - value 2
      - value 3
    tasks:
      - id: each-value
        type: io.kestra.core.tasks.debugs.Return
        format: "{{ task.id }} with current value '{{ taskrun.value }}'"

Handling each value in parallel but only 1 child task for each value at the same time.

yaml
id: each-parallel
namespace: io.kestra.tests

tasks:
  - id: each-parallel
    type: io.kestra.core.tasks.flows.EachParallel
    value: '["value 1", "value 2", "value 3"]'
    tasks:
      - id: seq
        type: io.kestra.core.tasks.flows.Sequential
        tasks:
        - id: t1
          type: io.kestra.plugin.scripts.shell.Commands
          commands:
            - 'echo "{{task.id}} > {{ parents[0].taskrun.value }}
            - 'sleep 1'
        - id: t2
          type: io.kestra.plugin.scripts.shell.Commands
          commands:
            - 'echo "{{task.id}} > {{ parents[0].taskrun.value }}
            - 'sleep 1'

Properties

concurrent

  • Type: integer
  • Dynamic:
  • Required: ✔️
  • Default: 0

Number of concurrent parallel tasks that can be running at any point in time.

If the value is 0, no limit exist and all the tasks will start at the same time.

tasks

  • Type: array
  • SubType: Task
  • Dynamic:
  • Required: ✔️
  • Min items: 1

value

  • Type:
    • string
    • array
  • Dynamic: ✔️
  • Required: ✔️

The list of values for this task.

The value can be passed as a string, a list of strings, or a list of objects.

errors

  • Type: array
  • SubType: Task
  • Dynamic:
  • Required:

List of tasks to run if any tasks failed on this FlowableTask.

Was this page helpful?