From 0b6b5d347f9abc5285e6a5aa63be5634c14438ef Mon Sep 17 00:00:00 2001 From: YannC Date: Tue, 24 Dec 2024 14:13:44 +0100 Subject: [PATCH] fix(core): Continue WaitFor loop if tasks are not failed close #6031 --- .../io/kestra/plugin/core/flow/WaitFor.java | 2 +- .../plugin/core/flow/WaitForCaseTest.java | 7 +++++ .../valids/waitfor-child-task-warning.yaml | 30 +++++++++++++++++++ .../io/kestra/jdbc/runner/JdbcRunnerTest.java | 6 ++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 core/src/test/resources/flows/valids/waitfor-child-task-warning.yaml diff --git a/core/src/main/java/io/kestra/plugin/core/flow/WaitFor.java b/core/src/main/java/io/kestra/plugin/core/flow/WaitFor.java index cf5d834fefe..2d5c0cd8d9f 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/WaitFor.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/WaitFor.java @@ -209,7 +209,7 @@ public boolean childTaskRunExecuted(Execution execution, TaskRun parentTaskRun) .stream() .filter(t -> t.getParentTaskRunId() != null && t.getParentTaskRunId().equals(parentTaskRun.getId()) - && t.getState().isSuccess() + && t.getState().isTerminated() ).count() == tasks.size(); } diff --git a/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java b/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java index 9fcce0bc3e6..aa48506d898 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/WaitForCaseTest.java @@ -61,4 +61,11 @@ public void waitforMultipleTasksFailed() throws TimeoutException, QueueException assertThat(execution.getState().getCurrent(), is(State.Type.FAILED)); assertThat(execution.getTaskRunList().getLast().attemptNumber(), is(1)); } + + public void waitForChildTaskWarning() throws TimeoutException, QueueException { + Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "waitfor-child-task-warning"); + + assertThat(execution.getState().getCurrent(), is(State.Type.FAILED)); + assertThat(execution.getTaskRunList().getLast().attemptNumber(), greaterThan(1)); + } } diff --git a/core/src/test/resources/flows/valids/waitfor-child-task-warning.yaml b/core/src/test/resources/flows/valids/waitfor-child-task-warning.yaml new file mode 100644 index 00000000000..a95d272dbae --- /dev/null +++ b/core/src/test/resources/flows/valids/waitfor-child-task-warning.yaml @@ -0,0 +1,30 @@ +id: waitfor-child-task-warning +namespace: io.kestra.tests + +tasks: + - id: loop + type: io.kestra.plugin.core.flow.WaitFor + condition: "{{ outputs.check_migration_task.vars['status'] == 'FINISHED' }}" + failOnMaxReached: true + checkFrequency: + interval: PT5S + maxDuration: PT10S + tasks: + + ## forcing a Warning + - id: allow_failure + type: io.kestra.plugin.scripts.shell.Commands + taskRunner: + type: io.kestra.plugin.core.runner.Process + allowFailure: true + commands: + - exit 1 + + - id: check_migration_task + type: io.kestra.plugin.scripts.shell.Commands + taskRunner: + type: io.kestra.plugin.scripts.runner.docker.Docker + entryPoint: [] + containerImage: "ubuntu:latest" + commands: + - "echo '::{\"outputs\":{\"status\": \"INPROGRESS\"}}::'" \ No newline at end of file diff --git a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java index 64436b2aac2..4a84422fc8d 100644 --- a/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java +++ b/jdbc/src/test/java/io/kestra/jdbc/runner/JdbcRunnerTest.java @@ -447,6 +447,12 @@ void waitforMultipleTasksFailed() throws Exception { waitForTestCaseTest.waitforMultipleTasksFailed(); } + @Test + @LoadFlows({"flows/valids/waitfor-child-task-warning.yaml"}) + void waitForChildTaskWarning() throws Exception { + waitForTestCaseTest.waitForChildTaskWarning(); + } + @Test @LoadFlows({"flows/valids/inputs-large.yaml"}) void flowTooLarge() throws Exception {