How to configure and enable a retry policy for a scheduled workflow execution

Hi
I am trying to configure a retry policy for a scheduled workflow execution (by scheduled workflow I mean this feature Features - Java SDK feature guide | Temporal Documentation). Unfortunately it seems not working for me.
I am expecting that when I add a RetryOptions to the Schedule → ScheduleActionStartWorkflow → WorkflowOptions then retries will be working according to the provided configuration. I haven’t seen any notes about additional actions that can be required to enable retries for scheduled workflow executions.
But maybe I am missing something and you can point me what I should do.
Notes:

  1. I am using Temporal v1.23.1.
  2. Activity retries are working as expected for scheduled workflows.
  3. When I fail the activity by throwing a RuntimeException then after activity retries exhausted the scheduled workflow execution fails without retries.
  4. I noticed that a retry policy that I set for a scheduled workflow is not visible for a workflow in the Temporal UI as usual (in Workflows → choose Workflow → Event History → WorkflowExecutionStarted event → Retry Policy).
  5. The same RetryOptions works as expected if I use them to trigger a single workflow execution (without a schedule).
    Example of a single workflow execution which I meant:
    workflowClient.newWorkflowStub(SomeWorkflow.class, workflowOptions).runSomeWorkflow(someInput);
  6. If I throw a RuntimeException not on the activity level but in the workflow implementation code then a scheduled workflow retries with a some weird retry policy (not following the rules which I set). For example: backoffCoefficient = 1.9; initialInterval = 5m; maxAttempts = 0; maxInterval = 3h. So I am expecting the following retry sequence: 5m → 9.5m → 18.05m → 34.295m → 65.1605 → … → 180m . But the actual retry sequence is: 0.037s → 0.058s → 10s → 10s → 14s → 20s → 27s → 47s → 78s.

Code example:

final var retryOptions = RetryOptions.newBuilder()
        .setMaximumAttempts(0)
        .setInitialInterval(Duration.ofMinutes(5))
        .setBackoffCoefficient(1.9)
        .setMaximumInterval(Duration.ofHours(3))
        .build();
    final var workflowOptions = WorkflowOptions.newBuilder()
        .setRetryOptions(retryOptions)
        .setWorkflowId(workflowIdGenerator.getScheduledWorkflowId(scheduleId))
        .setTaskQueue(TASK_QUEUE_NAME)
        .build();
    final var scheduleAction = ScheduleActionStartWorkflow.newBuilder()
            .setWorkflowType(SomeWorkflow.class)
            .setArguments(input)
            .setOptions(workflowOptions)
            .build();
    final var schedulePolicy = SchedulePolicy.newBuilder().build();
    final var scheduleSpec = ScheduleSpec.newBuilder()
        .setTimeZoneName(timezone)
        .setCronExpressions(cronSchedule)
        .build();
    final var schedule = Schedule.newBuilder()
        .setAction(scheduleAction)
        .setPolicy(schedulePolicy)
        .setSpec(scheduleSpec)
        .build();
    final var scheduleOptions = ScheduleOptions.newBuilder().build();
    scheduleClient.createSchedule(scheduleId, schedule, scheduleOptions);

My question is:
Is it possible to configure and enable a retry policy for a scheduled workflow and where I can find the information about it. Or maybe you can see an obvious mistake in my configuration.
Thank you in advance!

1 Like