@@ -406,10 +406,8 @@ public <V> Task<V> callSubOrchestrator(
406
406
407
407
private <V > Task <V > createAppropriateTask (TaskFactory <V > taskFactory , TaskOptions options ) {
408
408
// 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 ());
413
411
} else {
414
412
// Return a single vanilla task without any wrapper
415
413
return taskFactory .create ();
@@ -1170,25 +1168,34 @@ private boolean shouldRetry() {
1170
1168
return false ;
1171
1169
}
1172
1170
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 ) {
1185
1172
// We should never get here, but if we do, returning false is the natural behavior.
1186
1173
return false ;
1187
1174
}
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 ;
1188
1195
}
1189
1196
1190
1197
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 ()));
1192
1199
1193
1200
if (this .attemptNumber >= this .policy .getMaxNumberOfAttempts ()) {
1194
1201
// Max number of attempts exceeded
0 commit comments