Skip to content

Commit 152b89f

Browse files
authored
Merge pull request #25 from TheForbiddenAi/main
Allow for both retry handler and retry policy to be used at the same time
2 parents 61b62d9 + d7dcc56 commit 152b89f

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'io.dapr'
13-
version = '1.5.5'
13+
version = '1.5.6'
1414
archivesBaseName = 'durabletask-client'
1515

1616
def grpcVersion = '1.69.0'

client/src/main/java/io/dapr/durabletask/TaskOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public final class TaskOptions {
99
private final RetryPolicy retryPolicy;
1010
private final RetryHandler retryHandler;
1111

12-
private TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler) {
12+
public TaskOptions(RetryPolicy retryPolicy, RetryHandler retryHandler) {
1313
this.retryPolicy = retryPolicy;
1414
this.retryHandler = retryHandler;
1515
}

client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)