From c7c24d1fdef09a895c87874ebc20021c903a76c1 Mon Sep 17 00:00:00 2001 From: pragnareddye Date: Tue, 27 Jun 2023 04:48:17 -0700 Subject: [PATCH 1/2] Enable Infinitely Retrying Local Activity --- .../internal/worker/LocalActivityWorker.java | 15 --------------- .../testservice/TestServiceRetryState.java | 5 +---- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java index 91405af5f..d2faa35ee 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java @@ -140,10 +140,6 @@ private RetryDecision shouldRetry( throw (Error) attemptThrowable; } - if (isRetryPolicyNotSet(activityTask)) { - return new RetryDecision(RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET, null); - } - RetryOptions retryOptions = RetryOptionsUtils.toRetryOptions(activityTask.getRetryPolicy()); if (RetryOptionsUtils.isNotRetryable(retryOptions, attemptThrowable)) { @@ -375,10 +371,6 @@ private RetryState shouldStillRetry( @Nullable Failure previousLocalExecutionFailure) { int currentAttempt = activityTask.getAttempt(); - if (isRetryPolicyNotSet(activityTask)) { - return RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET; - } - RetryOptions retryOptions = RetryOptionsUtils.toRetryOptions(activityTask.getRetryPolicy()); if (previousLocalExecutionFailure != null @@ -764,13 +756,6 @@ private static Failure newTimeoutFailure(TimeoutType timeoutType, @Nullable Fail return result.build(); } - private static boolean isRetryPolicyNotSet( - PollActivityTaskQueueResponseOrBuilder pollActivityTask) { - return !pollActivityTask.hasScheduleToCloseTimeout() - && (!pollActivityTask.hasRetryPolicy() - || pollActivityTask.getRetryPolicy().getMaximumAttempts() <= 0); - } - private static boolean isNonRetryableApplicationFailure(@Nullable Throwable executionThrowable) { return executionThrowable instanceof ApplicationFailure && ((ApplicationFailure) executionThrowable).isNonRetryable(); diff --git a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java index f239e1825..e4c3eac8d 100644 --- a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java +++ b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java @@ -109,10 +109,6 @@ BackoffInterval getBackoffIntervalInSeconds(Optional errorType, Timestam } } } - Timestamp expirationTime = getExpirationTime(); - if (retryPolicy.getMaximumAttempts() == 0 && Timestamps.toMillis(expirationTime) == 0) { - return new BackoffInterval(RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET); - } if (retryPolicy.getMaximumAttempts() > 0 && getAttempt() >= retryPolicy.getMaximumAttempts()) { // currAttempt starts from 1. @@ -137,6 +133,7 @@ BackoffInterval getBackoffIntervalInSeconds(Optional errorType, Timestam nextInterval = maxInterval; } + Timestamp expirationTime = getExpirationTime(); long backoffInterval = nextInterval; Timestamp nextScheduleTime = Timestamps.add(currentTime, Durations.fromMillis(backoffInterval)); if (expirationTime.getNanos() != 0 From 91ade757142d32599bb5bbf05ffc1f2f81517403 Mon Sep 17 00:00:00 2001 From: pragnareddye Date: Sun, 2 Jul 2023 13:28:32 -0700 Subject: [PATCH 2/2] Addressing Comments --- .../internal/worker/LocalActivityWorker.java | 16 ++++++++++++++++ .../testservice/TestServiceRetryState.java | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java index d2faa35ee..13dafd06e 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/worker/LocalActivityWorker.java @@ -140,6 +140,10 @@ private RetryDecision shouldRetry( throw (Error) attemptThrowable; } + if (isRetryPolicyNotSet(activityTask)) { + return new RetryDecision(RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET, null); + } + RetryOptions retryOptions = RetryOptionsUtils.toRetryOptions(activityTask.getRetryPolicy()); if (RetryOptionsUtils.isNotRetryable(retryOptions, attemptThrowable)) { @@ -371,6 +375,10 @@ private RetryState shouldStillRetry( @Nullable Failure previousLocalExecutionFailure) { int currentAttempt = activityTask.getAttempt(); + if (isRetryPolicyNotSet(activityTask)) { + return RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET; + } + RetryOptions retryOptions = RetryOptionsUtils.toRetryOptions(activityTask.getRetryPolicy()); if (previousLocalExecutionFailure != null @@ -756,6 +764,14 @@ private static Failure newTimeoutFailure(TimeoutType timeoutType, @Nullable Fail return result.build(); } + private static boolean isRetryPolicyNotSet( + PollActivityTaskQueueResponseOrBuilder pollActivityTask) { + return !pollActivityTask.hasScheduleToCloseTimeout() + && !pollActivityTask.hasStartToCloseTimeout() + && (!pollActivityTask.hasRetryPolicy() + || pollActivityTask.getRetryPolicy().getMaximumAttempts() <= 0); + } + private static boolean isNonRetryableApplicationFailure(@Nullable Throwable executionThrowable) { return executionThrowable instanceof ApplicationFailure && ((ApplicationFailure) executionThrowable).isNonRetryable(); diff --git a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java index e4c3eac8d..f239e1825 100644 --- a/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java +++ b/temporal-test-server/src/main/java/io/temporal/internal/testservice/TestServiceRetryState.java @@ -109,6 +109,10 @@ BackoffInterval getBackoffIntervalInSeconds(Optional errorType, Timestam } } } + Timestamp expirationTime = getExpirationTime(); + if (retryPolicy.getMaximumAttempts() == 0 && Timestamps.toMillis(expirationTime) == 0) { + return new BackoffInterval(RetryState.RETRY_STATE_RETRY_POLICY_NOT_SET); + } if (retryPolicy.getMaximumAttempts() > 0 && getAttempt() >= retryPolicy.getMaximumAttempts()) { // currAttempt starts from 1. @@ -133,7 +137,6 @@ BackoffInterval getBackoffIntervalInSeconds(Optional errorType, Timestam nextInterval = maxInterval; } - Timestamp expirationTime = getExpirationTime(); long backoffInterval = nextInterval; Timestamp nextScheduleTime = Timestamps.add(currentTime, Durations.fromMillis(backoffInterval)); if (expirationTime.getNanos() != 0