-
Notifications
You must be signed in to change notification settings - Fork 52
[NO-ISSUE] Add wait to DSL #1294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
163ad9a
1504a5e
b9c9b74
1c1d994
fe71e87
fee59aa
a5896b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,83 @@ | ||||||||||||||
| /* | ||||||||||||||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||||||||||||||
| * | ||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||
| * | ||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
| * | ||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||
| * limitations under the License. | ||||||||||||||
| */ | ||||||||||||||
| package io.serverlessworkflow.fluent.spec; | ||||||||||||||
|
|
||||||||||||||
| import io.serverlessworkflow.api.types.DurationInline; | ||||||||||||||
| import io.serverlessworkflow.api.types.TimeoutAfter; | ||||||||||||||
| import io.serverlessworkflow.api.types.WaitTask; | ||||||||||||||
| import java.time.Duration; | ||||||||||||||
| import java.util.Objects; | ||||||||||||||
| import java.util.function.Consumer; | ||||||||||||||
|
|
||||||||||||||
| public class WaitTaskBuilder extends TaskBaseBuilder<WaitTaskBuilder> { | ||||||||||||||
|
|
||||||||||||||
| private final WaitTask waitTask; | ||||||||||||||
|
|
||||||||||||||
| public WaitTaskBuilder() { | ||||||||||||||
| this.waitTask = new WaitTask(); | ||||||||||||||
| setTask(this.waitTask); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| @Override | ||||||||||||||
| protected WaitTaskBuilder self() { | ||||||||||||||
| return this; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public WaitTaskBuilder wait(Consumer<TimeoutBuilder> waitConsumer) { | ||||||||||||||
| final TimeoutBuilder timeoutBuilder = new TimeoutBuilder(); | ||||||||||||||
| waitConsumer.accept(timeoutBuilder); | ||||||||||||||
| this.waitTask.setWait(timeoutBuilder.build().getAfter()); | ||||||||||||||
| return this; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public WaitTaskBuilder wait(String durationExpression) { | ||||||||||||||
|
||||||||||||||
| public WaitTaskBuilder wait(String durationExpression) { | |
| public WaitTaskBuilder wait(String durationExpression) { | |
| Objects.requireNonNull(durationExpression, "durationExpression must not be null"); | |
| if (durationExpression.isBlank()) { | |
| throw new IllegalArgumentException("durationExpression must not be blank"); | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,5 +27,11 @@ public interface ForkTaskFluent< | |
|
|
||
| SELF branches(Consumer<L> branchesConsumer); | ||
|
|
||
| default SELF branch(Consumer<L> branchConsumer) { | ||
| return branch(null, branchConsumer); | ||
| } | ||
|
|
||
| SELF branch(String name, Consumer<L> branchConsumer); | ||
|
|
||
|
Comment on lines
28
to
+35
|
||
| ForkTask build(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2020-Present The Serverless Workflow Specification Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.serverlessworkflow.fluent.spec.spi; | ||
|
|
||
| import io.serverlessworkflow.fluent.spec.TaskBaseBuilder; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public interface WaitFluent<SELF extends TaskBaseBuilder<?>, LIST> { | ||
|
|
||
| LIST wait(String name, Consumer<SELF> itemsConfigurer); | ||
|
|
||
| default LIST wait(Consumer<SELF> itemsConfigurer) { | ||
| return this.wait(null, itemsConfigurer); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WaitTaskBuilder.wait(Consumer) does not null-check the consumer and does not validate that the provided TimeoutBuilder actually sets a duration (inline or expression). As written, callers can build a wait task with wait=null or with a TimeoutAfter missing both durationInline and durationExpression, which will later cause an NPE in WaitExecutor when it calls Duration.parse(...). Consider requiring a non-null consumer and throwing an IllegalStateException when no duration is configured.