22// SPDX-License-Identifier: Apache-2.0
33package software .amazon .lambda .durable .operation ;
44
5+ import java .time .Instant ;
56import java .util .concurrent .CompletableFuture ;
67import java .util .function .Function ;
78import software .amazon .awssdk .services .lambda .model .ErrorObject ;
@@ -74,7 +75,7 @@ protected void replay(Operation existing) {
7475 }
7576 }
7677 // Step is pending retry - Start polling for PENDING -> READY transition
77- case PENDING -> pollReadyAndExecuteStepLogic (existing , attempt );
78+ case PENDING -> pollReadyAndExecuteStepLogic (existing . stepDetails (). nextAttemptTimestamp () , attempt );
7879 // Execute with current attempt
7980 case READY -> executeStepLogic (attempt );
8081 default ->
@@ -83,9 +84,8 @@ protected void replay(Operation existing) {
8384 }
8485 }
8586
86- private CompletableFuture <Void > pollReadyAndExecuteStepLogic (Operation existing , int attempt ) {
87- var nextAttemptInstant = existing .stepDetails ().nextAttemptTimestamp ();
88- return pollForOperationUpdates (nextAttemptInstant )
87+ private void pollReadyAndExecuteStepLogic (Instant nextAttemptInstant , int attempt ) {
88+ pollForOperationUpdates (nextAttemptInstant )
8989 .thenCompose (op -> op .status () == OperationStatus .READY
9090 ? CompletableFuture .completedFuture (op )
9191 : pollForOperationUpdates (nextAttemptInstant ))
@@ -163,19 +163,19 @@ private void handleStepFailure(Throwable exception, int attempt) {
163163
164164 if (isRetryable && retryDecision .shouldRetry ()) {
165165 // Send RETRY
166+ var retryDelayInSeconds = Math .toIntExact (retryDecision .delay ().toSeconds ());
166167 var retryUpdate = OperationUpdate .builder ()
167168 .action (OperationAction .RETRY )
168169 .error (errorObject )
169170 .stepOptions (StepOptions .builder ()
170171 // RetryDecisions always produce integer number of seconds greater or equals to
171172 // 1 (no sub-second numbers)
172- .nextAttemptDelaySeconds (
173- Math .toIntExact (retryDecision .delay ().toSeconds ()))
173+ .nextAttemptDelaySeconds (retryDelayInSeconds )
174174 .build ());
175175 sendOperationUpdate (retryUpdate );
176176
177177 // Poll for READY status and then execute the step again
178- pollReadyAndExecuteStepLogic (getOperation ( ), attempt + 1 );
178+ pollReadyAndExecuteStepLogic (Instant . now (). plusSeconds ( retryDelayInSeconds ), attempt + 1 );
179179 } else {
180180 // Send FAIL - retries exhausted
181181 var failUpdate =
0 commit comments