Google cloud cron.yaml schedule formatting for custom repetitive interval - google-app-engine

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?

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

Related

How to set a biweekly Cron job in App Engine

I'm trying to set a biweekly Cron job for a small Slack bot that I run at work off of App Engine. I previously had set it up in App Engine using the custom interval from the documentation to run every other week:
schedule: 1st,third Wednesday 10:00
I was waiting for the Slack bot to message today and it never came. Now the obvious solution is that I missed the 5th Wednesday of the month in my original scheduling statement. The problem here is that next week we will also get a message because it will again be the 1st Wednesday of the month. Is there a way to get the job to run as
schedule: every two Wednesday 10:00
or similar so that the job will run every two weeks?
In the documentation about formatting the schedule you can see under the "Custom Interval" tab what syntax options you have.
Given that you can specify days up to the 31st, I believe adding 5th to the expression you are using would fix the issue with "fifth" Wednesday:
schedule: 1st, 3rd, 5th Wednesday of month 10:00
If you don't mind the week day that you receive the update, you can also just set it to run every 14 days for simplicity:
schedule: 1, 14, 28 of month 10:00

How to make a cron job run during business hours on Google App Engine cron.yaml?

I've read the docs, but I'm scratching my head on how to do this. I want to run a cron job during business hours. So my cron.yaml would look something like:
cron:
- description: My Cool Cron Job
url: /myCoolCronJob.php
schedule: every 5 minutes from 06:00 to 19:00 every monday, tuesday, wednesday, thursday, friday
timezone: America/Los_Angeles
That doesn't work, obviously. But it should give you an idea of what I want to do. How can I make this cron job run during business hours?
The Schedule format doesn't offer a combination between the high-frequency
every N (hours|mins|minutes) ["from" (time) "to" (time)]
and the low frequency
("every"|ordinal) (days) ["of" (monthspec)] (time)
The way to obtain what you desire is to:
configure the high frequency portion of the schedule in cron.yaml:
schedule: every 5 minutes from 06:00 to 19:00
check the weekday condition inside the cron job itself, at the beginning and exiting without doing anything if the day of execution is Saturday or Sunday.

Google Application Engine Run cron job

How I can set GAE cron job to run at specific date at specific time
Like 10th April at 12:20 minute.Please provide syntax for this use case.
How to set IST time zone.
From the cron format documentation:
If you want more specific timing, you can specify the schedule as:
("every"|ordinal) (days) ["of" (monthspec)] (time)
Where:
ordinal specifies a comma separated list of "1st", "first" and so
forth (both forms are ok) days specifies a comma separated list of
days of the week (for example, "mon", "tuesday", with both short and
long forms being accepted); "every day" is equivalent to "every
mon,tue,wed,thu,fri,sat,sun" monthspec specifies a comma separated
list of month names (for example, "jan", "march", "sep"). If omitted,
implies every month. You can also say "month" to mean every month, as
in "1,8,15,22 of month 09:00". time specifies the time of day, as
HH:MM in 24 hour time.
So you'd want something like:
schedule: 10 of april 12:20
timezone: Asia/Kolkata
Possible solutions:
1) Create a cronjob that runs once a minute. When the current time equals your desired time, run your code.
2) If the specific time is in the next 30 days, use a Task with the eta property set: https://developers.google.com/appengine/docs/python/taskqueue/tasks#Task
3) Use some external service to setup a webhook that gets called at the proper time, make your code run when the webhook is called.

gae cron job for last day of every month

I want the schedule of a cron job to be the las day of every month. I've used this:
<schedule>last day of month 23:59</schedule>
Is it correct?
The easiest way to launch the job at first of month 00:00. You may tweak it to run few hours before setting the <timezone> to the timezone with more positive value than the desired one. If desired timezone is GMT than you may set the timezone of the cron job to Europe/Berlin and the job will be executed last day of the month at 23:00 GMT.
As per the documentation, the format for the Cron Expression for the kind that you are trying to create is:
("every"|ordinal) (days) ["of" (monthspec)] (time)
Where:
ordinal specifies a comma separated list of "1st", "first" and so forth (both forms are ok)
days specifies a comma separated list of days of the week (for example, "mon", "tuesday", with both short and long forms being accepted); "every day" is equivalent to "every mon,tue,wed,thu,fri,sat,sun"
monthspec specifies a comma separated list of month names (for example, "jan", "march", "sep"). If omitted, implies every month. You can also say "month" to mean every month, as in "1,8,15,22 of month 09:00".
time specifies the time of day, as HH:MM in 24 hour time.
I don't think there is a direct expression for what you are trying to do.
You might need to create multiple cron expressions. For e.g. 31 of month 09:00 would address 31st day of all months at 9:00 AM and it should address all months that have 31 days and so on.

How to run a Google App Engine cron job in in every weekday?

The complete description would be:
run a cron job in every 15 minutes, from 8:00 am to 5:00pm, every weekday (MON-FRI) pacific time. Also it would be better to be adjustable to daylight saving changes
How to do it in a cron.yaml in GAE?
You can't. Cron gives you one of two formats, but not both:
every N (hours|mins|minutes) ["from" (time) "to" (time)]
or
("every"|ordinal) (days) ["of" (monthspec)] (time)
Your best workaround would be to use:
every 15 minutes from 8:00 to 17:00
and then in code filter out weekends.
Worst case, you can create a new cron job for each day of the week! E.g.,
every monday ...
every tuesday ...
every wednesday ...
and of course skip the weekends.

Resources