Package io.kestra.core.tasks.flows
Class ForEachItem
java.lang.Object
io.kestra.core.models.tasks.Task
io.kestra.core.tasks.flows.ForEachItem
- All Implemented Interfaces:
ExecutableTask<ForEachItem.Output>
@Plugin(examples=@Example(title="Execute a subflow for each batch of items. The subflow `orders` is called from the parent flow `orders_parallel` using the `ForEachItem` task in order to start one subflow execution for each batch of items.\n```yaml\nid: orders\nnamespace: prod\n\ninputs:\n - name: order\n type: STRING\n\ntasks:\n - id: read_file\n type: io.kestra.plugin.scripts.shell.Commands\n runner: PROCESS\n commands:\n - cat \"{{ inputs.order }}\"\n\n - id: read_file_content\n type: io.kestra.core.tasks.log.Log\n message: \"{{ read(inputs.order) }}\"\n```\n",full=true,code="id: orders_parallel\nnamespace: prod\n\ntasks:\n - id: extract\n type: io.kestra.plugin.jdbc.duckdb.Query\n sql: |\n INSTALL httpfs;\n LOAD httpfs;\n SELECT *\n FROM read_csv_auto(\'https://raw.githubusercontent.com/kestra-io/datasets/main/csv/orders.csv\', header=True);\n store: true\n\n - id: each\n type: io.kestra.core.tasks.flows.ForEachItem\n items: \"{{ outputs.extract.uri }}\"\n batch:\n rows: 1\n namespace: prod\n flowId: orders\n wait: true # wait for the subflow execution\n transmitFailed: true # fail the task run if the subflow execution fails\n inputs:\n order: \"{{ taskrun.items }}\" # special variable that contains the items of the batch"))
public class ForEachItem
extends Task
implements ExecutableTask<ForEachItem.Output>
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.kestra.core.models.tasks.ExecutableTask
ExecutableTask.SubflowId -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateWorkerTaskExecutions(RunContext runContext, FlowExecutorInterface flowExecutorInterface, Flow currentFlow, Execution currentExecution, TaskRun currentTaskRun) Creates a list of WorkerTaskExecution for this task definition.createWorkerTaskResult(RunContext runContext, TaskRun taskRun, Flow flow, Execution execution) Creates a WorkerTaskResult for a given WorkerTaskExecutionbooleanWhether to wait for the execution(s) of the subflow before terminating this tasksMethods inherited from class io.kestra.core.models.tasks.Task
findById, findById, isFlowable, isSendToWorkerTask
-
Constructor Details
-
ForEachItem
public ForEachItem()
-
-
Method Details
-
createWorkerTaskExecutions
public List<WorkerTaskExecution<?>> createWorkerTaskExecutions(RunContext runContext, FlowExecutorInterface flowExecutorInterface, Flow currentFlow, Execution currentExecution, TaskRun currentTaskRun) throws InternalException Description copied from interface:ExecutableTaskCreates a list of WorkerTaskExecution for this task definition. Each WorkerTaskExecution will generate a subflow execution.- Specified by:
createWorkerTaskExecutionsin interfaceExecutableTask<ForEachItem.Output>- Throws:
InternalException
-
createWorkerTaskResult
public Optional<WorkerTaskResult> createWorkerTaskResult(RunContext runContext, TaskRun taskRun, Flow flow, Execution execution) Description copied from interface:ExecutableTaskCreates a WorkerTaskResult for a given WorkerTaskExecution- Specified by:
createWorkerTaskResultin interfaceExecutableTask<ForEachItem.Output>
-
waitForExecution
public boolean waitForExecution()Description copied from interface:ExecutableTaskWhether to wait for the execution(s) of the subflow before terminating this tasks- Specified by:
waitForExecutionin interfaceExecutableTask<ForEachItem.Output>
-
subflowId
- Specified by:
subflowIdin interfaceExecutableTask<ForEachItem.Output>- Returns:
- the subflow identifier, used by the flow topology and related dependency code.
-