How to create a schedule which can go to next year

Hi,

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

But I am getting the same error.

Can you help me solve this issue?

Hi @ddd

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();

Antonio

Thanks for the reply. I think I managed to achieve that by doing something like

StructuredCalendarSpec.newBuilder()
    .addAllMonth(
        listOf(
            Range.newBuilder()
                .setStart(1)
                .setEnd(1)
                .build(),
            Range.newBuilder()
                .setStart(6)
                .setEnd(6)
                .build()
        )
    )
    .build()

Hopefully it works.

But thanks for your solution too

1 Like