Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/for each #4477

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static List<NextTaskRun> resolveConcurrentNexts(
return Collections.emptyList();
}

long concurrencySlots = concurrency - nonTerminatedCount;
long concurrencySlots = concurrency == 0 ? Integer.MAX_VALUE : concurrency - nonTerminatedCount;

// first one
if (taskRuns.isEmpty()) {
Expand Down
26 changes: 19 additions & 7 deletions core/src/main/java/io/kestra/plugin/core/flow/ForEach.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -147,6 +148,7 @@ public class ForEach extends Sequential implements FlowableTask<VoidOutput> {
)
private Object values;

@PositiveOrZero
@NotNull
@Builder.Default
@Schema(
Expand All @@ -164,13 +166,23 @@ public class ForEach extends Sequential implements FlowableTask<VoidOutput> {
public GraphCluster tasksTree(Execution execution, TaskRun taskRun, List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ void concurrentWithParallel() throws TimeoutException {
assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
assertThat(execution.getTaskRunList(), hasSize(10));
}

@Test
void concurrentNoLimit() throws TimeoutException {
Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "foreach-concurrent-no-limit");

assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS));
assertThat(execution.getTaskRunList(), hasSize(7));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id: foreach-concurrent-no-limit
namespace: io.kestra.tests

tasks:
- id: for_each
type: io.kestra.plugin.core.flow.ForEach
values: ["value 1", "value 2", "value 3"]
concurrencyLimit: 0
tasks:
- id: log
type: io.kestra.plugin.core.log.Log
message: Processing {{taskrun.value}}
- id: shell
type: io.kestra.plugin.core.log.Log
message: 2nd task