From 277fa61194ded5483a78925f5da8aa6d9a82fa63 Mon Sep 17 00:00:00 2001 From: Maxim Fateev Date: Tue, 2 Jan 2024 17:03:27 -0800 Subject: [PATCH] Copy RetryOptions on empty ContinueAsNewOptions --- .../io/temporal/internal/sync/SyncWorkflowContext.java | 3 +++ .../java/io/temporal/workflow/ContinueAsNewTest.java | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java b/temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java index 6ec9cca5b..fb8ed08d0 100644 --- a/temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java +++ b/temporal-sdk/src/main/java/io/temporal/internal/sync/SyncWorkflowContext.java @@ -1137,6 +1137,9 @@ public void continueAsNew(ContinueAsNewInput input) { .determineUseCompatibleFlag( replayContext.getTaskQueue().equals(options.getTaskQueue()))); } + } else if (replayContext.getRetryOptions() != null) { + // Have to copy retry options as server doesn't copy them. + attributes.setRetryPolicy(toRetryPolicy(replayContext.getRetryOptions())); } List propagators = diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java index 5f6f9f5aa..63615de4a 100644 --- a/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java +++ b/temporal-sdk/src/test/java/io/temporal/workflow/ContinueAsNewTest.java @@ -98,7 +98,14 @@ public int execute(int count, String continueAsNewTaskQueue) { Map memo = new HashMap<>(); memo.put("myKey", "MyValue"); RetryOptions retryOptions = null; - // don't specify retryOptions on the first continue-as-new to test that they are copied from + // don't specify ContinueAsNewOptions on the first continue-as-new to test that RetryOptions + // are copied from the previous run. + if (count == INITIAL_COUNT) { + TestContinueAsNew next = Workflow.newContinueAsNewStub(TestContinueAsNew.class); + next.execute(count - 1, continueAsNewTaskQueue); + throw new RuntimeException("unreachable"); + } + // don't specify RetryOptions on the second continue-as-new to test that they are copied from // the previous run. if (count < INITIAL_COUNT - 1) { retryOptions = RetryOptions.newBuilder().setMaximumAttempts(5).build();