Skip to content

Commit 497fcbe

Browse files
authored
updating StartToCloseTimeout in fileprocessing sample (temporalio#169)
* updating StartToCloseTimeout in fileprocessing sample Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> * typo Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> * add ScheduleToStartTimeout Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> * fixes Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> * add comment Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
1 parent 8d5a80b commit 497fcbe

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/io/temporal/samples/fileprocessing/FileProcessingWorkflowImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@ private void processFileImpl(URL source, URL destination) {
7272
ActivityOptions hostActivityOptions =
7373
ActivityOptions.newBuilder()
7474
.setTaskQueue(downloaded.getHostTaskQueue())
75-
.setStartToCloseTimeout(Duration.ofSeconds(10))
75+
// Set the amount a time an activity task can stay in the task queue before its picked
76+
// up by a Worker. It allows us to support cases where
77+
// the activity worker crashes or restarts before the activity starts execution.
78+
// This timeout should be specified only when host specific activity task queues are
79+
// used like in this sample.
80+
// Note that scheduleToStart timeout is not retryable and retry options will ignore it.
81+
// This timeout has to be handled by Workflow code.
82+
.setScheduleToStartTimeout(Duration.ofSeconds(10))
83+
// Set the max time of a single activity execution attempt.
84+
// Activity is going to be executed by a Worker listening to the specified
85+
// host task queue. If the activity is started but then the activity worker crashes
86+
// for some reason, we want to make sure that it is retried after the specified timeout.
87+
// This timeout should be be as short as the longest possible execution of the Activity.
88+
.setStartToCloseTimeout(Duration.ofSeconds(2))
7689
.setRetryOptions(
7790
RetryOptions.newBuilder()
7891
.setInitialInterval(Duration.ofSeconds(1))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public static class GreetingWorkflowImpl implements GreetingWorkflow {
9898

9999
private static final int ACTIVITY_MAX_SLEEP_SECONDS = 30;
100100
private static final int ACTIVITY_MAX_CLEANUP_SECONDS = 5;
101-
private static final int ACTIVITY_START_TO_CLOSE_TIMEOUT = ACTIVITY_MAX_SLEEP_SECONDS + ACTIVITY_MAX_CLEANUP_SECONDS + 10;
101+
private static final int ACTIVITY_START_TO_CLOSE_TIMEOUT =
102+
ACTIVITY_MAX_SLEEP_SECONDS + ACTIVITY_MAX_CLEANUP_SECONDS + 10;
102103

103104
private static final String[] greetings =
104105
new String[] {"Hello", "Bye", "Hola", "Привет", "Oi", "Hallo"};

0 commit comments

Comments
 (0)