Skip to content

[NO-ISSUE] Add wait to DSL#1294

Open
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:wait
Open

[NO-ISSUE] Add wait to DSL#1294
mcruzdev wants to merge 1 commit intoserverlessworkflow:mainfrom
mcruzdev:wait

Conversation

@mcruzdev
Copy link
Copy Markdown
Collaborator

@mcruzdev mcruzdev commented Apr 8, 2026

This pull request introduces a new "wait" task type to the Serverless Workflow Java Fluent API, enabling workflows to pause execution for a specified duration.

New "wait" task support:

  • Added WaitTaskBuilder for configuring wait tasks with duration expressions, inline durations, or timeout builders. (fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/WaitTaskBuilder.java)
  • Extended the builder interfaces (TaskItemListBuilder, DoTaskBuilder, DoFluent, and new WaitFluent) to support adding wait tasks fluently, including auto-naming and configuration. (fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/TaskItemListBuilder.java, DoTaskBuilder.java, spi/DoFluent.java, spi/WaitFluent.java) [1] [2] [3] [4]
  • Enhanced the DSL with helper methods for creating wait tasks with various duration specifications. (fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java)

Testing and validation:

  • Added unit tests to verify wait task auto-naming, duration parsing, and DSL integration. (TaskItemDefaultNamingTest.java, DSLTest.java) [1] [2]
  • Introduced integration tests to ensure workflows wait the expected amount of time at runtime. (impl/test/src/test/java/io/serverlessworkflow/impl/test/WaitTest.java)

Bug fix:

  • Fixed a bug in WaitExecutor where duration components were not being added correctly, ensuring accurate wait times. (impl/core/src/main/java/io/serverlessworkflow/impl/executors/WaitExecutor.java)

Dependencies:

  • Added the Awaitility library as a test dependency to support timing assertions in wait-related tests. (impl/test/pom.xml)

Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
@mcruzdev mcruzdev requested a review from fjtirado as a code owner April 8, 2026 21:16
Copilot AI review requested due to automatic review settings April 8, 2026 21:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class wait task support to the Serverless Workflow Java Fluent API/DSL, along with runtime and test coverage, and fixes a duration-aggregation bug in the wait executor.

Changes:

  • Introduces WaitTaskBuilder and fluent interfaces to add wait tasks (including auto-naming support).
  • Adds DSL helper methods for constructing wait tasks from duration expressions or timeout builders.
  • Fixes WaitExecutor duration composition and adds new unit/integration tests for wait behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
impl/test/src/test/java/io/serverlessworkflow/impl/test/WaitTest.java New runtime/integration-style tests validating that workflows actually pause for a duration.
impl/test/pom.xml Adds Awaitility dependency for timing assertions (currently duplicated).
impl/core/src/main/java/io/serverlessworkflow/impl/executors/WaitExecutor.java Fixes duration accumulation to correctly add seconds/minutes/hours/days.
fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/TaskItemDefaultNamingTest.java Adds coverage for wait task auto-naming and inline-duration mapping.
fluent/spec/src/test/java/io/serverlessworkflow/fluent/spec/dsl/DSLTest.java Adds DSL helper coverage for wait tasks.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/WaitTaskBuilder.java New builder for configuring wait tasks via expression, Duration, or TimeoutBuilder.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/TaskItemListBuilder.java Adds fluent wait(...) task insertion into task lists.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/WaitFluent.java New SPI fluent interface for wait(...) task addition.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/DoFluent.java Extends the fluent task API to include wait(...) (SPI surface change).
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/dsl/DSL.java Adds DSL helper overloads for building wait tasks.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/DoTaskBuilder.java Wires wait(...) into the top-level do builder.
fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/BaseTaskItemListBuilder.java Adds TYPE_WAIT for deterministic auto-naming.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +98 to +102
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module already declares org.awaitility:awaitility earlier in the dependencies list (currently without an explicit ). Adding a second declaration here results in a duplicate dependency entry and can produce Maven duplicate-dependency warnings / unexpected effective scope. Prefer updating the existing Awaitility dependency to have test (or removing the earlier one) rather than adding a second block.

Copilot uses AI. Check for mistakes.
Comment on lines +79 to +83
try (WorkflowApplication app = WorkflowApplication.builder().build()) {
WorkflowDefinition definition = app.workflowDefinition(workflow);
long startNanos = System.nanoTime();
WorkflowModel model = definition.instance(Map.of()).start().join();
long elapsedMillis = Duration.ofNanos(System.nanoTime() - startNanos).toMillis();
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definition.instance(...).start().join() has no timeout. If the wait task (or scheduler) regresses and never completes, this test will hang the entire build. Consider adding an explicit upper bound (e.g., CompletableFuture.orTimeout / get(timeout) / assertTimeoutPreemptively) so failures terminate promptly with a clear error.

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +88
assertEquals(true, model.asMap().orElseThrow().get("finished"));
assertTrue(
elapsedMillis >= 5_000,
"Workflow should wait at least 5 seconds, but waited " + elapsedMillis + " ms");
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests enforce a real 5-second wall-clock delay (and the helper asserts against a hard-coded 5_000ms). This makes the suite slower and can be flaky on contended CI hosts. Consider reducing the exercised duration to ~1s (still catches the inline-duration aggregation bug) and/or using Awaitility with a small tolerance + an upper bound to keep runtime predictable.

Copilot uses AI. Check for mistakes.
Comment on lines 45 to 50
ForEachFluent<ForEachTaskBuilder<TaskItemListBuilder>, T>,
ForkFluent<ForkTaskBuilder, T>,
ListenFluent<ListenTaskBuilder, T>,
WaitFluent<WaitTaskBuilder, T>,
RaiseFluent<RaiseTaskBuilder, T>,
CallOpenAPIFluent<CallOpenAPITaskBuilder, T>,
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoFluent is in the public spi package; extending it with WaitFluent introduces a new abstract method (wait(String, Consumer)) and is a source/binary breaking change for any external implementations of DoFluent. If backward compatibility is important, consider providing a default implementation path (e.g., default methods) or clearly treating this as a major-version/SPI-breaking change.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants