Skip to content

Commit 50e4a45

Browse files
authored
Fix heartbeating in HelloCancellationScope (temporalio#311)
1 parent a715660 commit 50e4a45

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/io/temporal/samples/hello/HelloCancellationScope.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
124124
Workflow.newActivityStub(
125125
GreetingActivities.class,
126126
ActivityOptions.newBuilder()
127+
// if heartbeat timeout is not set, activity heartbeats will be throttled to one
128+
// every 30 seconds
129+
// which is too rare for the cancellations to be delivered in this example.
130+
.setHeartbeatTimeout(Duration.ofSeconds(5))
127131
.setStartToCloseTimeout(Duration.ofSeconds(ACTIVITY_START_TO_CLOSE_TIMEOUT))
128132
.setCancellationType(ActivityCancellationType.WAIT_CANCELLATION_COMPLETED)
129133
.build());
@@ -191,7 +195,7 @@ public String composeGreeting(String greeting, String name) {
191195

192196
// simulate a random time this activity should execute for
193197
Random random = new Random();
194-
int seconds = random.nextInt(GreetingWorkflowImpl.ACTIVITY_MAX_SLEEP_SECONDS - 2) + 2;
198+
int seconds = random.nextInt(GreetingWorkflowImpl.ACTIVITY_MAX_SLEEP_SECONDS - 5) + 5;
195199
System.out.println("Activity for " + greeting + " going to take " + seconds + " seconds");
196200

197201
for (int i = 0; i < seconds; i++) {

0 commit comments

Comments
 (0)