diff --git a/client/build.gradle b/client/build.gradle index 2d8cfdc8..26b3c2ba 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -10,7 +10,7 @@ plugins { } group 'io.dapr' -version = '1.5.5' +version = '1.5.6' archivesBaseName = 'durabletask-client' def grpcVersion = '1.69.0' diff --git a/client/src/main/java/io/dapr/durabletask/TaskOptions.java b/client/src/main/java/io/dapr/durabletask/TaskOptions.java index cafb669c..50f47273 100644 --- a/client/src/main/java/io/dapr/durabletask/TaskOptions.java +++ b/client/src/main/java/io/dapr/durabletask/TaskOptions.java @@ -9,7 +9,7 @@ public final class TaskOptions { private final RetryPolicy retryPolicy; private final RetryHandler retryHandler; - private TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler) { + public TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler) { this.retryPolicy = retryPolicy; this.retryHandler = retryHandler; } diff --git a/client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java b/client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java index 569cc717..213c77f2 100644 --- a/client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java +++ b/client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java @@ -406,10 +406,8 @@ public Task callSubOrchestrator( private Task createAppropriateTask(TaskFactory taskFactory, TaskOptions options) { // Retry policies and retry handlers will cause us to return a RetriableTask - if (options != null && options.hasRetryPolicy()) { - return new RetriableTask(this, taskFactory, options.getRetryPolicy()); - } if (options != null && options.hasRetryHandler()) { - return new RetriableTask(this, taskFactory, options.getRetryHandler()); + if (options != null && (options.hasRetryPolicy() || options.hasRetryHandler())) { + return new RetriableTask(this, taskFactory, options.getRetryPolicy(), options.getRetryHandler()); } else { // Return a single vanilla task without any wrapper return taskFactory.create(); @@ -1170,25 +1168,34 @@ private boolean shouldRetry() { return false; } - if (this.policy != null) { - logger.warning("Performing retires based on policy"); - - return this.shouldRetryBasedOnPolicy(); - } else if (this.handler != null) { - RetryContext retryContext = new RetryContext( - this.context, - this.attemptNumber, - this.lastFailure, - this.totalRetryTime); - return this.handler.handle(retryContext); - } else { + if(this.policy == null && this.handler == null) { // We should never get here, but if we do, returning false is the natural behavior. return false; } + + RetryContext retryContext = new RetryContext( + this.context, + this.attemptNumber, + this.lastFailure, + this.totalRetryTime); + + // These must default to true if not provided, so it is possible to use only one of them at a time + boolean shouldRetryBasedOnPolicy = this.policy != null ? this.shouldRetryBasedOnPolicy() : true; + boolean shouldRetryBasedOnHandler = this.handler != null ? this.handler.handle(retryContext) : true; + + if (this.policy != null) { + logger.info(() -> String.format("shouldRetryBasedOnPolicy: %s", shouldRetryBasedOnPolicy)); + } + + if (this.handler != null) { + logger.info(() -> String.format("shouldRetryBasedOnHandler: %s", shouldRetryBasedOnHandler)); + } + + return shouldRetryBasedOnPolicy && shouldRetryBasedOnHandler; } private boolean shouldRetryBasedOnPolicy() { - logger.warning(() -> String.format("%d retries out of total %d performed ", this.attemptNumber, this.policy.getMaxNumberOfAttempts())); + logger.warning(() -> String.format("Retry Policy: %d retries out of total %d performed ", this.attemptNumber, this.policy.getMaxNumberOfAttempts())); if (this.attemptNumber >= this.policy.getMaxNumberOfAttempts()) { // Max number of attempts exceeded