@@ -406,10 +406,8 @@ public <V> Task<V> callSubOrchestrator(
406406
407407 private <V > Task <V > createAppropriateTask (TaskFactory <V > taskFactory , TaskOptions options ) {
408408 // Retry policies and retry handlers will cause us to return a RetriableTask<V>
409- if (options != null && options .hasRetryPolicy ()) {
410- return new RetriableTask <V >(this , taskFactory , options .getRetryPolicy ());
411- } if (options != null && options .hasRetryHandler ()) {
412- return new RetriableTask <V >(this , taskFactory , options .getRetryHandler ());
409+ if (options != null && (options .hasRetryPolicy () || options .hasRetryHandler ())) {
410+ return new RetriableTask <V >(this , taskFactory , options .getRetryPolicy (), options .getRetryHandler ());
413411 } else {
414412 // Return a single vanilla task without any wrapper
415413 return taskFactory .create ();
@@ -1170,25 +1168,34 @@ private boolean shouldRetry() {
11701168 return false ;
11711169 }
11721170
1173- if (this .policy != null ) {
1174- logger .warning ("Performing retires based on policy" );
1175-
1176- return this .shouldRetryBasedOnPolicy ();
1177- } else if (this .handler != null ) {
1178- RetryContext retryContext = new RetryContext (
1179- this .context ,
1180- this .attemptNumber ,
1181- this .lastFailure ,
1182- this .totalRetryTime );
1183- return this .handler .handle (retryContext );
1184- } else {
1171+ if (this .policy == null && this .handler == null ) {
11851172 // We should never get here, but if we do, returning false is the natural behavior.
11861173 return false ;
11871174 }
1175+
1176+ RetryContext retryContext = new RetryContext (
1177+ this .context ,
1178+ this .attemptNumber ,
1179+ this .lastFailure ,
1180+ this .totalRetryTime );
1181+
1182+ // These must default to true if not provided, so it is possible to use only one of them at a time
1183+ boolean shouldRetryBasedOnPolicy = this .policy != null ? this .shouldRetryBasedOnPolicy () : true ;
1184+ boolean shouldRetryBasedOnHandler = this .handler != null ? this .handler .handle (retryContext ) : true ;
1185+
1186+ if (this .policy != null ) {
1187+ logger .info (() -> String .format ("shouldRetryBasedOnPolicy: %s" , shouldRetryBasedOnPolicy ));
1188+ }
1189+
1190+ if (this .handler != null ) {
1191+ logger .info (() -> String .format ("shouldRetryBasedOnHandler: %s" , shouldRetryBasedOnHandler ));
1192+ }
1193+
1194+ return shouldRetryBasedOnPolicy && shouldRetryBasedOnHandler ;
11881195 }
11891196
11901197 private boolean shouldRetryBasedOnPolicy () {
1191- logger .warning (() -> String .format ("%d retries out of total %d performed " , this .attemptNumber , this .policy .getMaxNumberOfAttempts ()));
1198+ logger .warning (() -> String .format ("Retry Policy: %d retries out of total %d performed " , this .attemptNumber , this .policy .getMaxNumberOfAttempts ()));
11921199
11931200 if (this .attemptNumber >= this .policy .getMaxNumberOfAttempts ()) {
11941201 // Max number of attempts exceeded
0 commit comments