11package io .temporal .samples .polling .infrequentwithretryafter ;
22
33import io .temporal .activity .Activity ;
4+ import io .temporal .failure .ApplicationErrorCategory ;
45import io .temporal .failure .ApplicationFailure ;
56import io .temporal .samples .polling .PollingActivities ;
67import io .temporal .samples .polling .TestService ;
1011import java .time .format .DateTimeFormatter ;
1112
1213public 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