Skip to content

Commit

Permalink
Fix schedule workflow action retry policy (#2082)
Browse files Browse the repository at this point in the history
Fix schedule workflow action retry policy
  • Loading branch information
Quinn-With-Two-Ns authored May 29, 2024
1 parent 0d7ae22 commit ae6597f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package io.temporal.internal.client;

import static io.temporal.internal.common.HeaderUtils.toHeaderGrpc;
import static io.temporal.internal.common.RetryOptionsUtils.toRetryPolicy;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
Expand All @@ -36,6 +37,7 @@
import io.temporal.api.workflow.v1.NewWorkflowExecutionInfo;
import io.temporal.client.WorkflowOptions;
import io.temporal.client.schedules.*;
import io.temporal.common.RetryOptions;
import io.temporal.common.context.ContextPropagator;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.converter.EncodedValues;
Expand Down Expand Up @@ -128,6 +130,11 @@ public ScheduleAction actionToProto(io.temporal.client.schedules.ScheduleAction
workflowRequest.setInput(inputArgs.get());
}

RetryOptions retryOptions = wfOptions.getRetryOptions();
if (retryOptions != null) {
workflowRequest.setRetryPolicy(toRetryPolicy(retryOptions));
}

if (startWorkflowAction.getOptions().getMemo() != null) {
Map<String, Payload> memo = new HashMap<>();
for (Map.Entry<String, Object> item :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import io.temporal.api.enums.v1.ScheduleOverlapPolicy;
import io.temporal.client.WorkflowOptions;
import io.temporal.common.RetryOptions;
import io.temporal.common.converter.EncodedValues;
import io.temporal.common.interceptors.ScheduleClientInterceptor;
import io.temporal.testing.internal.SDKTestWorkflowRule;
Expand Down Expand Up @@ -301,10 +302,12 @@ public void describeSchedules() {
.setMemo(Collections.singletonMap("memokey2", "memoval2"))
.build();
String scheduleId = UUID.randomUUID().toString();
RetryOptions retryOptions = RetryOptions.newBuilder().setMaximumAttempts(1).build();
WorkflowOptions wfOptions =
WorkflowOptions.newBuilder()
.setWorkflowId("test")
.setTaskQueue(testWorkflowRule.getTaskQueue())
.setRetryOptions(retryOptions)
.setMemo(Collections.singletonMap("memokey1", "memoval1"))
.build();

Expand Down Expand Up @@ -360,7 +363,7 @@ public void describeSchedules() {
//
Assert.assertEquals(scheduleId, description.getId());
Assert.assertEquals("memoval2", description.getMemo("memokey2", String.class));
//
// Assert action
Assert.assertEquals(
ScheduleActionStartWorkflow.class, description.getSchedule().getAction().getClass());
ScheduleActionStartWorkflow startWfAction =
Expand All @@ -372,6 +375,7 @@ public void describeSchedules() {
(EncodedValues) startWfAction.getOptions().getMemo().get("memokey1");
String memoValue = encodedMemo.get(0, String.class);
Assert.assertEquals("memoval1", memoValue);
Assert.assertEquals(startWfAction.getOptions().getRetryOptions(), retryOptions);

Check failure on line 378 in temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleTest.java

View workflow job for this annotation

GitHub Actions / JUnit Test Report

ScheduleTest.describeSchedules

java.lang.AssertionError: expected:<RetryOptions{initialInterval=PT1S, backoffCoefficient=2.0, maximumAttempts=1, maximumInterval=null, doNotRetry=[]}> but was:<RetryOptions{initialInterval=null, backoffCoefficient=0.0, maximumAttempts=1, maximumInterval=null, doNotRetry=null}>
Raw output
java.lang.AssertionError: expected:<RetryOptions{initialInterval=PT1S, backoffCoefficient=2.0, maximumAttempts=1, maximumInterval=null, doNotRetry=[]}> but was:<RetryOptions{initialInterval=null, backoffCoefficient=0.0, maximumAttempts=1, maximumInterval=null, doNotRetry=null}>
	at org.junit.Assert.fail(Assert.java:89)
	at org.junit.Assert.failNotEquals(Assert.java:835)
	at org.junit.Assert.assertEquals(Assert.java:120)
	at org.junit.Assert.assertEquals(Assert.java:146)
	at io.temporal.client.schedules.ScheduleTest.describeSchedules(ScheduleTest.java:378)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.lang.Thread.run(Thread.java:829)
//
Assert.assertEquals(
ScheduleSpec.newBuilder(description.getSchedule().getSpec())
Expand Down

0 comments on commit ae6597f

Please sign in to comment.