Skip to content

Commit 4fafe25

Browse files
committed
Add sleep method with options for timer
The sleep function in a workflow is syntactic sugar over the timer method. Today I was going to do a change in one of my services to sleep for a few mins but wanted to add a summary and found out this is only available on the timer api. Let me know what you think of this change!
1 parent f5df5c4 commit 4fafe25

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowOutboundCallsInterceptor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ public DynamicUpdateHandler getHandler() {
738738

739739
void sleep(Duration duration);
740740

741+
void sleep(Duration duration, TimerOptions options);
742+
741743
boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition);
742744

743745
void await(String reason, Supplier<Boolean> unblockCondition);

temporal-sdk/src/main/java/io/temporal/common/interceptors/WorkflowOutboundCallsInterceptorBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public void sleep(Duration duration) {
6565
next.sleep(duration);
6666
}
6767

68+
@Override
69+
public void sleep(Duration duration, TimerOptions options) {
70+
next.sleep(duration, options);
71+
}
72+
6873
@Override
6974
public boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition) {
7075
return next.await(timeout, reason, unblockCondition);

temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,11 @@ public void sleep(Duration duration) {
13151315
newTimer(duration).get();
13161316
}
13171317

1318+
@Override
1319+
public void sleep(Duration duration, TimerOptions options) {
1320+
newTimer(duration, options).get();
1321+
}
1322+
13181323
@Override
13191324
public boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition) {
13201325
Promise<Void> timer = newTimer(timeout);

temporal-testing/src/main/java/io/temporal/testing/TestActivityEnvironmentInternal.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ public void sleep(Duration duration) {
384384
throw new UnsupportedOperationException("not implemented");
385385
}
386386

387+
@Override
388+
public void sleep(Duration duration, TimerOptions options) {
389+
throw new UnsupportedOperationException("not implemented");
390+
}
391+
387392
@Override
388393
public boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition) {
389394
throw new UnsupportedOperationException("not implemented");

temporal-testing/src/main/java/io/temporal/testing/internal/TracingWorkerInterceptor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ public void sleep(Duration duration) {
217217
next.sleep(duration);
218218
}
219219

220+
@Override
221+
public void sleep(Duration duration, TimerOptions options) {
222+
if (!WorkflowUnsafe.isReplaying()) {
223+
trace.add("sleep " + duration);
224+
}
225+
next.sleep(duration, options);
226+
}
227+
220228
@Override
221229
public boolean await(Duration timeout, String reason, Supplier<Boolean> unblockCondition) {
222230
if (!WorkflowUnsafe.isReplaying()) {

0 commit comments

Comments
 (0)