I’m developing functionality where I need to send reminders to users after every 12 hours. I want to configure a schedule such that it’ll initiate a workflow 12 hours after schedule creation time.
First approach -
In the first approach I initiated schedule with setStartDelay
of 12 hours. In this case first workflow run was scheduled at 12:00 UTC instead of 12 hours after the schedule creation time.
Schedule schedule = Schedule.newBuilder()
.setAction(
ScheduleActionStartWorkflow.newBuilder()
.setWorkflowType(ReminderWorkflow.class)
.setArguments(workflowInput)
.setOptions(
WorkflowOptions.newBuilder()
.setStartDelay(Duration.ofHours(12))
.setWorkflowId(referenceId)
.setTaskQueue(taskQueue)
.build())
.build())
.setSpec(ScheduleSpec.newBuilder()
.setIntervals(Collections.singletonList(new ScheduleIntervalSpec(Duration.ofHours(12))))
.setTimeZoneName("Asia/Kolkata")
.build())
.build();
Schedule details
Schedule Created: 2024-09-12 UTC 10:28:32.28
Upcoming Runs as observed from temporal UI
2024-09-12 UTC 12:00:00.00
2024-09-13 UTC 00:00:00.00
2024-09-13 UTC 12:00:00.00
2024-09-14 UTC 00:00:00.00
2024-09-14 UTC 12:00:00.00
Second approach -
In second approach I removed the setStartDelay
and used setCalendars
. In this case also the first workflow run was scheduled at 12:00 UTC instead of 12 hours after the schedule creation time. Additionally, second workflow run was scheduled after the 12 hours.
LocalDateTime scheduleStartTime = LocalDateTime.now().plusHours(12);
Schedule schedule = Schedule.newBuilder()
.setAction(
ScheduleActionStartWorkflow.newBuilder()
.setWorkflowType(ReminderWorkflow.class)
.setArguments(workflowInput)
.setOptions(
WorkflowOptions.newBuilder()
.setWorkflowId(referenceId)
.setTaskQueue(taskQueue)
.build())
.build())
.setSpec(ScheduleSpec.newBuilder()
.setCalendars(
Collections.singletonList(
ScheduleCalendarSpec.newBuilder()
.setDayOfMonth(Collections.singletonList(new ScheduleRange(scheduleStartTime.getDayOfMonth())))
.setHour(Collections.singletonList(new ScheduleRange(scheduleStartTime.getHour())))
.setMinutes(Collections.singletonList(new ScheduleRange(scheduleStartTime.getMinute())))
.setSeconds(Collections.singletonList(new ScheduleRange(scheduleStartTime.getSecond())))
.build()))
.setIntervals(Collections.singletonList(new ScheduleIntervalSpec(Duration.ofHours(12))))
.setTimeZoneName("Asia/Kolkata")
.build())
.build();
Schedule details
Schedule Created: 2024-09-12 UTC 10:26:28.07
Upcoming Runs as observed from temporal UI
2024-09-12 UTC 12:00:00.00
2024-09-12 UTC 22:26:28.00
2024-09-13 UTC 00:00:00.00
2024-09-13 UTC 12:00:00.00
2024-09-14 UTC 00:00:00.00
Also setTimeZoneName
doesn’t seem to have an impact on the outcome.
Is there something wrong with the way schedule is configured?