Skip to content

Commit a650078

Browse files
Switch poller sample to use ApplicationErrorCategory (#743)
Switch poller sample to use ApplicationErrorCategory
1 parent 62a35ce commit a650078

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ subprojects {
2626
ext {
2727
otelVersion = '1.30.1'
2828
otelVersionAlpha = "${otelVersion}-alpha"
29-
javaSDKVersion = '1.28.1'
29+
javaSDKVersion = '1.30.0'
3030
camelVersion = '3.22.1'
3131
jarVersion = '1.0.0'
3232
}

core/src/main/java/io/temporal/samples/polling/infrequent/InfrequentPollingActivityImpl.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package io.temporal.samples.polling.infrequent;
22

3-
import io.temporal.activity.Activity;
3+
import io.temporal.failure.ApplicationErrorCategory;
4+
import io.temporal.failure.ApplicationFailure;
45
import io.temporal.samples.polling.PollingActivities;
56
import io.temporal.samples.polling.TestService;
67

78
public class InfrequentPollingActivityImpl implements PollingActivities {
8-
private TestService service;
9+
private final TestService service;
910

1011
public InfrequentPollingActivityImpl(TestService service) {
1112
this.service = service;
@@ -17,7 +18,13 @@ public String doPoll() {
1718
return service.getServiceResult();
1819
} catch (TestService.TestServiceException e) {
1920
// We want to rethrow the service exception so we can poll via activity retries
20-
throw Activity.wrap(e);
21+
throw ApplicationFailure.newBuilder()
22+
.setMessage(e.getMessage())
23+
.setType(e.getClass().getName())
24+
.setCause(e)
25+
// This failure is expected so we set it as benign to avoid excessive logging
26+
.setCategory(ApplicationErrorCategory.BENIGN)
27+
.build();
2128
}
2229
}
2330
}

core/src/main/java/io/temporal/samples/polling/infrequentwithretryafter/InfrequentPollingWithRetryAfterActivityImpl.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.temporal.samples.polling.infrequentwithretryafter;
22

33
import io.temporal.activity.Activity;
4+
import io.temporal.failure.ApplicationErrorCategory;
45
import io.temporal.failure.ApplicationFailure;
56
import io.temporal.samples.polling.PollingActivities;
67
import io.temporal.samples.polling.TestService;
@@ -10,7 +11,7 @@
1011
import java.time.format.DateTimeFormatter;
1112

1213
public class InfrequentPollingWithRetryAfterActivityImpl implements PollingActivities {
13-
private TestService service;
14+
private final TestService service;
1415
final DateTimeFormatter ISO_FORMATTER = DateTimeFormatter.ISO_DATE_TIME;
1516

1617
public InfrequentPollingWithRetryAfterActivityImpl(TestService service) {
@@ -32,13 +33,16 @@ public String doPoll() {
3233
// which is the test service exception
3334
// and delay which is the interval to next retry based on test service retry-after directive
3435
System.out.println("Activity next retry in: " + e.getRetryAfterInMinutes() + " minutes");
35-
throw ApplicationFailure.newFailureWithCauseAndDelay(
36-
e.getMessage(),
37-
e.getClass().getName(),
38-
e,
39-
// here we set the next retry interval based on Retry-After duration given to us by our
36+
throw ApplicationFailure.newBuilder()
37+
.setMessage(e.getMessage())
38+
.setType(e.getClass().getName())
39+
.setCause(e)
40+
// Here we set the next retry interval based on Retry-After duration given to us by our
4041
// service
41-
Duration.ofMinutes(e.getRetryAfterInMinutes()));
42+
.setNextRetryDelay(Duration.ofMinutes(e.getRetryAfterInMinutes()))
43+
// This failure is expected so we set it as benign to avoid excessive logging
44+
.setCategory(ApplicationErrorCategory.BENIGN)
45+
.build();
4246
}
4347
}
4448
}

0 commit comments

Comments
 (0)