I am trying to create a schedule which get triggers every 6 months.
Here are some examples I tried,
Example 1:
Every 6 months from today
So start month is month of today (March) & end month is 6 months from today (September)
This works fine
Example 2:
Every 6 month from October 1st
So start month is October & end month is April
This fails with the error INVALID_ARGUMENT: Invalid schedule spec: invalid calendar spec: Month End is before Start or not in range [1-12]
As I understood Start month October & end month April cause the error.
To solve this, I tried to include
Start month = October
Start year = 2023
End month = April
End year = 2024
Setting a cron expression and remaining runs should work
Schedule schedule =
Schedule.newBuilder()
.setAction(action)
.setSpec(
ScheduleSpec.newBuilder()
.setCronExpressions(
List.of(
"0 0 1 */6 *")) // "At 00:00, on day 1 of the month, every 6 months"
.build())
.setState(
ScheduleState.newBuilder()
.setRemainingActions(2) // only two times
.setLimitedAction(true)
.build())
.build();