Search code examples
google-app-enginegoogle-cloud-platformcron

Google cloud cron.yaml schedule formatting for custom repetitive interval


I'm struggling to format a cron schedule for gcp properly and the docs aren't really helping me out.

Cron #1: Run every 50 minutes from 11:00 to 21:00 only on the months from march to october inclusive

  schedule: every 50 minutes from 11:00 to 21:00 of mar,apr,may,jun,jul,aug,sep,oct

Cron #2: Run every day at 22:00 only on the months from march to october inclusive

  schedule: every day 22:00 of mar,apr,may,jun,jul,aug,sep,oct

Neither of those work, but they were one of my attempts. What am I doing wrong here?


Solution

  • Referring to the Formatting the schedule docs below.

    There is no supported syntax for your 1st cron:

    • specifying minutes in an [INTERVAL_VALUE] is only supported by END-TIME INTERVAL and START-TIME INTERVAL formats, but neither of them allows specifying months in the [INTERVAL_SCOPE].
    • the only format supporting month specification in [INTERVAL_SCOPE] is CUSTOM INTERVAL, but that only supports day specifications in [INTERVAL_VALUE].

    But you can achieve an equivalent functionality by using the finer time specification in cron.yaml and making a check for the remaining conditions inside the cron job itself, doing nothing if the condition is not met. So your 1st cron would be achieved with:

    • this cron.yaml entry:

      schedule: every 50 minutes from 11:00 to 21:00
      
    • an additional check for the current month inside the cron job itself, doing nothing (just returning) if the month is Jan, Feb, Nov or Dec.

    Your 2nd cron is possible using a CUSTOM INTERVAL, you just need to place the hour at the end of the [INTERVAL_SCOPE]. From the doc:

    [INTERVAL_SCOPE]: Specifies a clause that corresponds with the specified [INTERVAL_VALUE]. Custom intervals can include the of [MONTH] clause, which specifies a single month in a year, or a comma-separated list of multiple months. You must also define a specific time for when you want the job to run, for example: of [MONTH] [HH:MM].

    So your entry would be:

    schedule: every day of mar,apr,may,jun,jul,aug,sep,oct 22:00