@@ -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,29 @@ 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 ();
1184
+ boolean shouldRetryBasedOnHandler = this .handler == null || this .handler .handle (retryContext );
1185
+
1186
+ logger .info (() -> String .format ("Retry policy provided: %s, shouldRetryBasedOnPolicy: %s" , this .policy != null , shouldRetryBasedOnPolicy ));
1187
+ logger .info (() -> String .format ("Retry handler provided: %s, shouldRetryBasedOnHandler: %s" , this .handler != null , shouldRetryBasedOnHandler ));
1188
+
1189
+ return shouldRetryBasedOnPolicy && shouldRetryBasedOnHandler ;
1188
1190
}
1189
1191
1190
1192
private boolean shouldRetryBasedOnPolicy () {
1191
- logger .warning (() -> String .format ("%d retries out of total %d performed " , this .attemptNumber , this .policy .getMaxNumberOfAttempts ()));
1193
+ logger .warning (() -> String .format ("Retry Policy: %d retries out of total %d performed " , this .attemptNumber , this .policy .getMaxNumberOfAttempts ()));
1192
1194
1193
1195
if (this .attemptNumber >= this .policy .getMaxNumberOfAttempts ()) {
1194
1196
// Max number of attempts exceeded
0 commit comments