From 8c52603293ea4eb772d46cf3687b887e02728f7a Mon Sep 17 00:00:00 2001 From: yoyounik Date: Tue, 22 Oct 2024 14:57:05 +0530 Subject: [PATCH 01/10] Updated time duration to 30 seconds --- core/src/test/resources/flows/valids/sleep.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/resources/flows/valids/sleep.yml b/core/src/test/resources/flows/valids/sleep.yml index 24748d7199..471ec3f112 100644 --- a/core/src/test/resources/flows/valids/sleep.yml +++ b/core/src/test/resources/flows/valids/sleep.yml @@ -4,4 +4,4 @@ namespace: io.kestra.tests tasks: - id: sleep type: io.kestra.core.tasks.test.Sleep - duration: 1000 \ No newline at end of file + duration: 3000 #30 seconds updated \ No newline at end of file From 97eab40389bc50912b9dbf0fc91bc47a427d4850 Mon Sep 17 00:00:00 2001 From: yoyounik Date: Tue, 22 Oct 2024 23:52:04 +0530 Subject: [PATCH 02/10] added Wait.java class, wait-task-flow.yaml --- .../io/kestra/plugin/core/debug/Wait.java | 55 +++++++++++++++++++ .../flows/valids/wait-task-flow.yaml | 17 ++++++ 2 files changed, 72 insertions(+) create mode 100644 core/src/main/java/io/kestra/plugin/core/debug/Wait.java create mode 100644 core/src/test/resources/flows/valids/wait-task-flow.yaml diff --git a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java new file mode 100644 index 0000000000..a927ed21d8 --- /dev/null +++ b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java @@ -0,0 +1,55 @@ +package io.kestra.plugin.core.debug; + +import io.kestra.core.models.annotations.Example; +import io.kestra.core.models.annotations.Plugin; +import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.tasks.Task; +import io.kestra.core.runners.RunContext; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +@SuperBuilder +@ToString +@EqualsAndHashCode +@Getter +@NoArgsConstructor +@Schema( + title = "A task that waits for a specified duration before proceeding." +) +@Plugin( + examples = { + @Example( + code = """ + id: wait + type: io.kestra.plugin.core.debug.Wait + duration: "PT5S" + """ + ) + } +) +public class Wait extends Task { + @Schema( + title = "Duration to wait", + description = "The time duration in ISO-8601 format (e.g., `PT5S` for 5 seconds)." + ) + @PluginProperty + @NotNull + private Duration duration; + + public Void run(RunContext runContext) throws Exception { + runContext.logger().info("Waiting for {}", duration); + + // Wait for the specified duration + TimeUnit.MILLISECONDS.sleep(duration.toMillis()); + + return null; + } +} diff --git a/core/src/test/resources/flows/valids/wait-task-flow.yaml b/core/src/test/resources/flows/valids/wait-task-flow.yaml new file mode 100644 index 0000000000..ec75928ea6 --- /dev/null +++ b/core/src/test/resources/flows/valids/wait-task-flow.yaml @@ -0,0 +1,17 @@ +id: wait-task-flow +namespace: io.kestra.tests + +tasks: + - id: wait + type: io.kestra.plugin.core.debug.Wait + delay: PT10S # Waits for 10 seconds before proceeding + + - id: next-task + type: io.kestra.plugin.core.scripts.Shell + commands: + - echo "Wait task completed" + +triggers: + - id: schedule + type: io.kestra.plugin.core.trigger.Schedule + cron: "0 * * * *" From 7acc11ec639afd8108fe3c437f80b50b272e6b05 Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 00:49:52 +0530 Subject: [PATCH 03/10] updated the duration and added all other changes except test --- core/src/main/java/io/kestra/plugin/core/debug/Wait.java | 2 +- core/src/test/resources/flows/sleep-task.yml | 7 +++++++ core/src/test/resources/flows/valids/sleep.yml | 2 +- core/src/test/resources/flows/valids/wait-task-flow.yaml | 5 +---- 4 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 core/src/test/resources/flows/sleep-task.yml diff --git a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java index a927ed21d8..b8f9147451 100644 --- a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java +++ b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java @@ -29,7 +29,7 @@ @Example( code = """ id: wait - type: io.kestra.plugin.core.debug.Wait + type: wait.task duration: "PT5S" """ ) diff --git a/core/src/test/resources/flows/sleep-task.yml b/core/src/test/resources/flows/sleep-task.yml new file mode 100644 index 0000000000..492491e0c5 --- /dev/null +++ b/core/src/test/resources/flows/sleep-task.yml @@ -0,0 +1,7 @@ +id: sleep-task-flow +namespace: io.kestra.tests + +tasks: + - id: sleep + type: io.kestra.core.tasks.scripts.Bash + script: sleep 30 \ No newline at end of file diff --git a/core/src/test/resources/flows/valids/sleep.yml b/core/src/test/resources/flows/valids/sleep.yml index 471ec3f112..24748d7199 100644 --- a/core/src/test/resources/flows/valids/sleep.yml +++ b/core/src/test/resources/flows/valids/sleep.yml @@ -4,4 +4,4 @@ namespace: io.kestra.tests tasks: - id: sleep type: io.kestra.core.tasks.test.Sleep - duration: 3000 #30 seconds updated \ No newline at end of file + duration: 1000 \ No newline at end of file diff --git a/core/src/test/resources/flows/valids/wait-task-flow.yaml b/core/src/test/resources/flows/valids/wait-task-flow.yaml index ec75928ea6..ea220ded89 100644 --- a/core/src/test/resources/flows/valids/wait-task-flow.yaml +++ b/core/src/test/resources/flows/valids/wait-task-flow.yaml @@ -11,7 +11,4 @@ tasks: commands: - echo "Wait task completed" -triggers: - - id: schedule - type: io.kestra.plugin.core.trigger.Schedule - cron: "0 * * * *" + From 618dcbcba4feb6f59e5e3eaa992d745e10b99247 Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 12:45:24 +0530 Subject: [PATCH 04/10] added the waitTaskTest method for testing --- .../java/io/kestra/plugin/core/flow/SequentialTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java index f29df1babf..72ed277ec1 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java @@ -21,6 +21,15 @@ void sequential() throws TimeoutException, QueueException { assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); } + @Test + void waitTaskTest() throws TimeoutException, QueueException { + Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "wait-task-flow"); + + // Assert that the execution state is SUCCESS after the wait task completes + assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); + } + + @Test void sequentialWithGlobalErrors() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sequential-with-global-errors"); From 76042b45ea26ff96e68600dfe13d81136b1a519d Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 12:56:03 +0530 Subject: [PATCH 05/10] removed sleep-task.yml changes --- core/src/test/resources/flows/sleep-task.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/core/src/test/resources/flows/sleep-task.yml b/core/src/test/resources/flows/sleep-task.yml index 492491e0c5..e69de29bb2 100644 --- a/core/src/test/resources/flows/sleep-task.yml +++ b/core/src/test/resources/flows/sleep-task.yml @@ -1,7 +0,0 @@ -id: sleep-task-flow -namespace: io.kestra.tests - -tasks: - - id: sleep - type: io.kestra.core.tasks.scripts.Bash - script: sleep 30 \ No newline at end of file From cb0e67da7b33e4de814a6da2578090f9bf0fd89a Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 13:01:31 +0530 Subject: [PATCH 06/10] removed the type with id: wait type: io.kestra.plugin.core.debug.Wait duration: "PT5S" --- core/src/main/java/io/kestra/plugin/core/debug/Wait.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java index b8f9147451..a927ed21d8 100644 --- a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java +++ b/core/src/main/java/io/kestra/plugin/core/debug/Wait.java @@ -29,7 +29,7 @@ @Example( code = """ id: wait - type: wait.task + type: io.kestra.plugin.core.debug.Wait duration: "PT5S" """ ) From 6b6a4d623bbe4960ee09d243da99d9566ce2928b Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 13:06:13 +0530 Subject: [PATCH 07/10] removed the type with id: wait type: io.kestra.plugin.core.debug.Wait duration: "PT5S" Also updated the wait.java in the flow package --- .../main/java/io/kestra/plugin/core/{debug => flow}/Wait.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename core/src/main/java/io/kestra/plugin/core/{debug => flow}/Wait.java (97%) diff --git a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java b/core/src/main/java/io/kestra/plugin/core/flow/Wait.java similarity index 97% rename from core/src/main/java/io/kestra/plugin/core/debug/Wait.java rename to core/src/main/java/io/kestra/plugin/core/flow/Wait.java index a927ed21d8..e845e4dbe2 100644 --- a/core/src/main/java/io/kestra/plugin/core/debug/Wait.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/Wait.java @@ -1,4 +1,4 @@ -package io.kestra.plugin.core.debug; +package io.kestra.plugin.core.flow; import io.kestra.core.models.annotations.Example; import io.kestra.core.models.annotations.Plugin; From 3771ca91240003c438788edf12fc5bf42153d0e7 Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 13:16:51 +0530 Subject: [PATCH 08/10] removed the yaml file update the type --- core/src/main/java/io/kestra/plugin/core/flow/Wait.java | 2 +- core/src/test/resources/flows/sleep-task.yml | 0 core/src/test/resources/flows/valids/wait-task-flow.yaml | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 core/src/test/resources/flows/sleep-task.yml diff --git a/core/src/main/java/io/kestra/plugin/core/flow/Wait.java b/core/src/main/java/io/kestra/plugin/core/flow/Wait.java index e845e4dbe2..a635d7a7b7 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/Wait.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/Wait.java @@ -29,7 +29,7 @@ @Example( code = """ id: wait - type: io.kestra.plugin.core.debug.Wait + type: io.kestra.plugin.core.flow.Wait duration: "PT5S" """ ) diff --git a/core/src/test/resources/flows/sleep-task.yml b/core/src/test/resources/flows/sleep-task.yml deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/src/test/resources/flows/valids/wait-task-flow.yaml b/core/src/test/resources/flows/valids/wait-task-flow.yaml index ea220ded89..2e842b609d 100644 --- a/core/src/test/resources/flows/valids/wait-task-flow.yaml +++ b/core/src/test/resources/flows/valids/wait-task-flow.yaml @@ -3,7 +3,7 @@ namespace: io.kestra.tests tasks: - id: wait - type: io.kestra.plugin.core.debug.Wait + type: io.kestra.plugin.core.flow.Wait delay: PT10S # Waits for 10 seconds before proceeding - id: next-task From 70a891f6205cd648152d209689f83c1826358b46 Mon Sep 17 00:00:00 2001 From: yoyounik Date: Wed, 23 Oct 2024 15:10:56 +0530 Subject: [PATCH 09/10] Wait.java changed to Sleep.java, wait-task-flow.yml changed to sleep-task-flow.yml and changes inside it to Sleep. sleep.yml's type has been changed. --- .../io/kestra/plugin/core/flow/{Wait.java => Sleep.java} | 2 +- .../java/io/kestra/plugin/core/flow/SequentialTest.java | 2 +- .../valids/{wait-task-flow.yaml => sleep-task-flow.yaml} | 6 +++--- core/src/test/resources/flows/valids/sleep.yml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) rename core/src/main/java/io/kestra/plugin/core/flow/{Wait.java => Sleep.java} (97%) rename core/src/test/resources/flows/valids/{wait-task-flow.yaml => sleep-task-flow.yaml} (73%) diff --git a/core/src/main/java/io/kestra/plugin/core/flow/Wait.java b/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java similarity index 97% rename from core/src/main/java/io/kestra/plugin/core/flow/Wait.java rename to core/src/main/java/io/kestra/plugin/core/flow/Sleep.java index a635d7a7b7..674592d99e 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/Wait.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java @@ -35,7 +35,7 @@ ) } ) -public class Wait extends Task { +public class Sleep extends Task { @Schema( title = "Duration to wait", description = "The time duration in ISO-8601 format (e.g., `PT5S` for 5 seconds)." diff --git a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java index 72ed277ec1..c875a257dd 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java @@ -22,7 +22,7 @@ void sequential() throws TimeoutException, QueueException { } @Test - void waitTaskTest() throws TimeoutException, QueueException { + void sleepTaskTest() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "wait-task-flow"); // Assert that the execution state is SUCCESS after the wait task completes diff --git a/core/src/test/resources/flows/valids/wait-task-flow.yaml b/core/src/test/resources/flows/valids/sleep-task-flow.yaml similarity index 73% rename from core/src/test/resources/flows/valids/wait-task-flow.yaml rename to core/src/test/resources/flows/valids/sleep-task-flow.yaml index 2e842b609d..afb4eebf4f 100644 --- a/core/src/test/resources/flows/valids/wait-task-flow.yaml +++ b/core/src/test/resources/flows/valids/sleep-task-flow.yaml @@ -1,9 +1,9 @@ -id: wait-task-flow +id: sleep-task-flow namespace: io.kestra.tests tasks: - - id: wait - type: io.kestra.plugin.core.flow.Wait + - id: sleep + type: io.kestra.plugin.core.flow.Sleep delay: PT10S # Waits for 10 seconds before proceeding - id: next-task diff --git a/core/src/test/resources/flows/valids/sleep.yml b/core/src/test/resources/flows/valids/sleep.yml index 24748d7199..54848fa931 100644 --- a/core/src/test/resources/flows/valids/sleep.yml +++ b/core/src/test/resources/flows/valids/sleep.yml @@ -3,5 +3,5 @@ namespace: io.kestra.tests tasks: - id: sleep - type: io.kestra.core.tasks.test.Sleep + type: io.kestra.plugin.core.flow.Sleep duration: 1000 \ No newline at end of file From c8b5e882bb75a9590c2c4967bdfeaeff33722527 Mon Sep 17 00:00:00 2001 From: YannC Date: Wed, 23 Oct 2024 14:55:30 +0200 Subject: [PATCH 10/10] fix(*): polishing --- .../io/kestra/plugin/core/flow/Sleep.java | 18 ++++++++------- .../plugin/core/flow/SequentialTest.java | 9 -------- .../io/kestra/plugin/core/flow/SleepTest.java | 23 +++++++++++++++++++ .../flows/valids/sleep-task-flow.yaml | 7 +----- .../src/test/resources/flows/valids/sleep.yml | 2 +- 5 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java diff --git a/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java b/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java index 674592d99e..38d4feac82 100644 --- a/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java +++ b/core/src/main/java/io/kestra/plugin/core/flow/Sleep.java @@ -3,7 +3,9 @@ import io.kestra.core.models.annotations.Example; import io.kestra.core.models.annotations.Plugin; import io.kestra.core.models.annotations.PluginProperty; +import io.kestra.core.models.tasks.RunnableTask; import io.kestra.core.models.tasks.Task; +import io.kestra.core.models.tasks.VoidOutput; import io.kestra.core.runners.RunContext; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotNull; @@ -22,29 +24,29 @@ @Getter @NoArgsConstructor @Schema( - title = "A task that waits for a specified duration before proceeding." + title = "A task that sleep for a specified duration before proceeding." ) @Plugin( examples = { @Example( code = """ - id: wait - type: io.kestra.plugin.core.flow.Wait - duration: "PT5S" - """ + id: sleep + type: io.kestra.plugin.core.flow.Sleep + duration: "PT5S" + """ ) } ) -public class Sleep extends Task { +public class Sleep extends Task implements RunnableTask { @Schema( - title = "Duration to wait", + title = "Duration to sleep", description = "The time duration in ISO-8601 format (e.g., `PT5S` for 5 seconds)." ) @PluginProperty @NotNull private Duration duration; - public Void run(RunContext runContext) throws Exception { + public VoidOutput run(RunContext runContext) throws Exception { runContext.logger().info("Waiting for {}", duration); // Wait for the specified duration diff --git a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java index c875a257dd..f29df1babf 100644 --- a/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java +++ b/core/src/test/java/io/kestra/plugin/core/flow/SequentialTest.java @@ -21,15 +21,6 @@ void sequential() throws TimeoutException, QueueException { assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); } - @Test - void sleepTaskTest() throws TimeoutException, QueueException { - Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "wait-task-flow"); - - // Assert that the execution state is SUCCESS after the wait task completes - assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); - } - - @Test void sequentialWithGlobalErrors() throws TimeoutException, QueueException { Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sequential-with-global-errors"); diff --git a/core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java b/core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java new file mode 100644 index 0000000000..50e31a8286 --- /dev/null +++ b/core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java @@ -0,0 +1,23 @@ +package io.kestra.plugin.core.flow; + +import io.kestra.core.models.executions.Execution; +import io.kestra.core.models.flows.State; +import io.kestra.core.queues.QueueException; +import io.kestra.core.runners.AbstractMemoryRunnerTest; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.TimeoutException; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +public class SleepTest extends AbstractMemoryRunnerTest { + @Test + void sleepTaskTest() throws TimeoutException, QueueException { + Execution execution = runnerUtils.runOne(null, "io.kestra.tests", "sleep-task-flow"); + + assertThat(execution.getState().getCurrent(), is(State.Type.SUCCESS)); + } + + +} diff --git a/core/src/test/resources/flows/valids/sleep-task-flow.yaml b/core/src/test/resources/flows/valids/sleep-task-flow.yaml index afb4eebf4f..1cff3b3663 100644 --- a/core/src/test/resources/flows/valids/sleep-task-flow.yaml +++ b/core/src/test/resources/flows/valids/sleep-task-flow.yaml @@ -4,11 +4,6 @@ namespace: io.kestra.tests tasks: - id: sleep type: io.kestra.plugin.core.flow.Sleep - delay: PT10S # Waits for 10 seconds before proceeding - - - id: next-task - type: io.kestra.plugin.core.scripts.Shell - commands: - - echo "Wait task completed" + duration: PT2S diff --git a/core/src/test/resources/flows/valids/sleep.yml b/core/src/test/resources/flows/valids/sleep.yml index 54848fa931..24748d7199 100644 --- a/core/src/test/resources/flows/valids/sleep.yml +++ b/core/src/test/resources/flows/valids/sleep.yml @@ -3,5 +3,5 @@ namespace: io.kestra.tests tasks: - id: sleep - type: io.kestra.plugin.core.flow.Sleep + type: io.kestra.core.tasks.test.Sleep duration: 1000 \ No newline at end of file