forked from temporalio/edu-101-java-code
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGreetingWorkflowImpl.java
More file actions
35 lines (27 loc) · 1.4 KB
/
GreetingWorkflowImpl.java
File metadata and controls
35 lines (27 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package greetingworkflow;
// This example illustrates how to use a retry policy in a Workflow.
// Since the code change is entirely within the Workflow Implementation, only that
// file is provided here.
import io.temporal.activity.ActivityOptions;
import io.temporal.workflow.Workflow;
import io.temporal.common.RetryOptions;
import java.time.Duration;
public class GreetingWorkflowImpl implements GreetingWorkflow {
RetryOptions retryOptions = RetryOptions.newBuilder()
.setInitialInterval(Duration.ofSeconds(15)) // first retry will occur after 15 seconds
.setBackoffCoefficient(2.0) // double the delay after each retry
.setMaximumInterval(Duration.ofSeconds(60)) // up to a maximum delay of 60 seconds
.setMaximumAttempts(100) // fail the Activity after 100 attempts
.build()
ActivityOptions options = ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(5))
.setRetryOptions(retryOptions)
.build();
private final GreetingActivities activities = Workflow.newActivityStub(GreetingActivities.class, options);
@Override
public String greetSomeone(String name) {
String spanishGreeting = activities.greetInSpanish(name);
String spanishFarewell = activities.farewellInSpanish(name);
return "\n" + spanishGreeting + "\n" + spanishFarewell;
}
}