Skip to content

Commit

Permalink
fix(*): polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Skraye committed Oct 23, 2024
1 parent 70a891f commit c8b5e88
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
18 changes: 10 additions & 8 deletions core/src/main/java/io/kestra/plugin/core/flow/Sleep.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<VoidOutput> {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
23 changes: 23 additions & 0 deletions core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java
Original file line number Diff line number Diff line change
@@ -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));
}


}
7 changes: 1 addition & 6 deletions core/src/test/resources/flows/valids/sleep-task-flow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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


2 changes: 1 addition & 1 deletion core/src/test/resources/flows/valids/sleep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c8b5e88

Please sign in to comment.