How to handle missed action in Schedules?

I am using temporal cloud with Java SDK.

Let’s say I have a workflow scheduled to run daily at 1 AM UTC. If, for some reason, our service, which is hosting the workers, is down during 1 AM UTC and comes back around 2 AM UTC, will the schedule get executed at 2 AM UTC?

Is there a way for me to control this behavior? For example, if the service comes back at 2 AM UTC, then I want to execute the schedule at 2 AM. If the service is down for 24 hours and comes back at 1 AM UTC the next day, then I do not want to execute two schedules back to back.

I have read the documentation for ScheduleBackFill, but it is unclear if it can be used to control the above.

Schedules have overlap policy you can define - What is a Temporal Workflow? | Temporal Platform Documentation
that could help. Also you can get the workflow execution time in your workflow code, in java:

Workflow.currentTimeMillis()

as well as time when execution was created:

Workflow.getInfo().getRunStartedTimestampMillis()

that you could use to make a decision on maybe explicitly failing your execution or continue.

Thanks for replying,

Can you let me know how do I specify the catchup-window as mentioned in the above link for java? For example let’s say I want it to set it to 23 hours for the above example from the default 1 year.

You can specify it when you create your schedule, for example:

Schedule schedule =
        Schedule.newBuilder()
                 // ...
                .setPolicy(SchedulePolicy.newBuilder()
                        .setCatchupWindow(...)
                        .build())
                .build();

Note that the catchup window only applies to creating the workflow, not to it starting running. I.e., if the Temporal server is up and working at 1 AM UTC, then the scheduled workflow will be created, regardless of whether your workers are running. It would just be stuck at the first workflow task until the workers come back, which could be 1 hour or 24 hours. If it did get to 24 hours, though, then the overlap policy would control whether the old one or the new one ran after that.

If you want to say something like, ignore this run if it’s been 23 hours since the workflow was created, then you could handle it in the schedule itself by checking the current time against the scheduled start time right at the beginning of the workflow. You could also set a workflow timeout of 23 hours.

1 Like

Thanks @dnr .

If you want to say something like, ignore this run if it’s been 23 hours since the workflow was created, then you could handle it in the schedule itself by checking the current time against the scheduled start time right at the beginning of the workflow

This I guess I have to do by using Workflow.getInfo().getRunStartedTimestampMillis() and Workflow.currentTimeMillis() which @tihomir mentioned above.

You could also set a workflow timeout of 23 hours.

Can you let me know how do I specify the workflow timeout? I do not see anything in ScheduleOptions. I am using java SDK 1.22.2.

Can you let me know how do I specify the workflow timeout?

Think idea was to set run timeout in WorkflowOptions. Just note that if set your workers would not be able to react to it (when reached service just times out execution which is not reported to your workers).