-
Notifications
You must be signed in to change notification settings - Fork 948
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #4879 Co-authored-by: YannC <ycoornaert@kestra.io>
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.kestra.plugin.core.flow; | ||
|
||
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; | ||
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 sleep for a specified duration before proceeding." | ||
) | ||
@Plugin( | ||
examples = { | ||
@Example( | ||
code = """ | ||
id: sleep | ||
type: io.kestra.plugin.core.flow.Sleep | ||
duration: "PT5S" | ||
""" | ||
) | ||
} | ||
) | ||
public class Sleep extends Task implements RunnableTask<VoidOutput> { | ||
@Schema( | ||
title = "Duration to sleep", | ||
description = "The time duration in ISO-8601 format (e.g., `PT5S` for 5 seconds)." | ||
) | ||
@PluginProperty | ||
@NotNull | ||
private Duration duration; | ||
|
||
public VoidOutput run(RunContext runContext) throws Exception { | ||
runContext.logger().info("Waiting for {}", duration); | ||
|
||
// Wait for the specified duration | ||
TimeUnit.MILLISECONDS.sleep(duration.toMillis()); | ||
|
||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/test/java/io/kestra/plugin/core/flow/SleepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
id: sleep-task-flow | ||
namespace: io.kestra.tests | ||
|
||
tasks: | ||
- id: sleep | ||
type: io.kestra.plugin.core.flow.Sleep | ||
duration: PT2S | ||
|
||
|