From 7a639601bd1bc7aed263969d402a59b05fe43984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 30 Jul 2024 11:08:13 +0200 Subject: [PATCH] fix(core): ForEach graph should be sequential when concurrencyLimit=1 Fixes #4474 --- .../io/kestra/plugin/core/flow/ForEach.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java b/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java index 8b76d4c020..5af633727c 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/ForEach.java @@ -18,6 +18,7 @@ import io.kestra.core.utils.GraphUtils; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; import lombok.*; import lombok.experimental.SuperBuilder; @@ -147,6 +148,7 @@ public class ForEach extends Sequential implements FlowableTask { ) private Object values; + @PositiveOrZero @NotNull @Builder.Default @Schema( @@ -164,13 +166,23 @@ public class ForEach extends Sequential implements FlowableTask { public GraphCluster tasksTree(Execution execution, TaskRun taskRun, List parentValues) throws IllegalVariableEvaluationException { GraphCluster subGraph = new GraphCluster(this, taskRun, parentValues, RelationType.DYNAMIC); - GraphUtils.parallel( - subGraph, - this.getTasks(), - this.getErrors(), - taskRun, - execution - ); + if (concurrencyLimit == 1) { + GraphUtils.sequential( + subGraph, + this.getTasks(), + this.getErrors(), + taskRun, + execution + ); + } else { + GraphUtils.parallel( + subGraph, + this.getTasks(), + this.getErrors(), + taskRun, + execution + ); + } return subGraph; }