Temporal Cron Backoff

Hello team,

Is there anything I can do to control the initial backoff when Temporal execute my cron? I have a cron workflow that runs at every 10th minutes, and I would like it to finish in 10 minutes so I set an execution timeout. However, some times the initial backoff is too long(10 minutes set to firstWorkflowTaskBackoff when I looked at events). I wonder if I can control the max backoff? Thanks in advance!

firstWorkflowTaskBackoff is set by the time your client starts workflow execution that defines a cron in WorkflowOptions, and the cron definition.

When you start a cron workflow (from client) the workflow execution is started on the service right away.
You will see your workflow in “Running” status, and firstWorkflowTaskBackoff is a timer that fires depending on the cron def. So for example if you start your workflow at let’s say
11:30am and your cron schedule is
setCronSchedule("10 * * * *")
firstWorkflowTaskBackoff should be around 40 minutes.
Service then waits for this duration before placing a workflow task onto the queue for your worker to pick it up and start execution of your workflow method.

Once your workflow method execution starts, it is not preempted (terminated) if it runs for in this case longer than 1 hour. If your workflow execution takes let’s say 70 minutes (so from let’s say 12:10am to 1:20pm), as soon as this run completes, Temporal uses continueAsNew internally to right away schedule a new execution, and then calculates the firstWorkflowTaskBackoff based on the time this new execution is started (and your cron definition).

So just to use the example again, if you define your cron as “10 * * * *”
and your workflow exec let’s say takes 65 minutes:

  1. Client requests workflow start at 11:30am
  2. Workflow execution is created at 11:30am with a firstWorkflowTaskBackoff of 40 minutes
  3. Workflow method execution is started at 12:10, and let’s say completes at 1:15pm
  4. New workflow execution is started right away at 1:15pm with a firstWorkflowTaskBackoff set to 55 minutes
    5 …

One thing to note is that workflow execution/run timeouts you set in WorkflowOptions are timers that start when the workflow execution starts (WorkflowExecutionStarted is placed in the workflow exec history). This means that if your execution/run timeouts are shorter than the calculated firstWorkflowTaskBackoff from your cron, your workflow execution will time out.
If your cron workflow does not complete, but rather fails or times out (or is terminated), no new execution is going to be scheduled. So it’s best from cron workflows not to set these timeouts to allow workflow execution to complete, so new one will get created according to your cron def.

If you need custom control over periodic workflow executions, you can define this in your workflow code.
See the updatable timer example where you have full control over your periodic timers and can updated them via signals, and it also supports cancellations.

Hope this helps.

1 Like