2

Currently I have a function deployed in Google Functions, which is triggered by a Cron Job using Cloud Scheduler in Google Cloud Platform.

The Cron Job Frequency in unix is the following: 0 9 1-7,15-21,29-31 * 1

Which means that it should be triggered every Monday in a Month at 9:00 AM, which day falls between 1st and 7th, 15th and 21st, 29th and 31st, respectively. Or in other words, it gets triggered every 2 weeks.

The following image (cron job testers) also confirms what I am intending to do.

https://lh3.googleusercontent.com/-f1RNnvdj_ww/YFC_WDxKSSI/AAAAAAAAAcY/_YVdgq2mxyksZHDJRQ_4m9jMylw8G2IEwCK8BGAsYHg/s0/2021-03-16.png?authuser=0

As expected, yesterday March 15th (Monday) it got triggered, however today March 16th (Tuesday) it got triggered as well

I am wondering if this has happen to any of you and whether it's a problem with my cron job or either Google Cloud Scheduler doesn't interpret it this way.

Any help/experience is highly appreciated!!

jccampanero
  • 50,989
  • 3
  • 20
  • 49
Jhony Chu
  • 46
  • 3

1 Answers1

3

Crontab uses OR when both day of month and day of week are provided: please, see your screenshot, it shows that your process will run tomorrow, March 17th, at 9:00.

I honestly do not know the actual reason of this crontab exception: for curiosity, I came across this SO question, which provides a possible explanation.

In order to express similar conditions, in a general use case, you can take advantage of crontab expressions, see for example this SO question or this other in Server Fault, but I do not know whether they are or not applicable in Google Cloud Scheduler.

Perhaps, instead of a cron expression, you can use the so-called English Style Schedule, the same used on App Engine - see the tab Custom interval, to define your expressions, maybe it can be more suitable for your use case.

jccampanero
  • 50,989
  • 3
  • 20
  • 49
  • Hi jccampero, thanks for your reply. I have read through your suggestions and unfortunately GCP doesn’t allow to use these js files inside a cron job in their cloud functions application. On the other hand side, regarding the yaml files to schedule a function only works for App Engines and not for Cloud Functions (similar to AWS lambda). If you have any suggestion on how I should modify my cron job so that I can achieve what I need is highly appreciated!!! – Jhony Chu Mar 17 '21 at 13:35
  • 1
    Hi @JhonyChu. Thank you very much for your feedback. Yes, of course, you do not have the ability to use yams files or something like that, but I mean that you can use the same kind of expressions that can be used in App Engine. For example, when defining the Cloud Scheduler cron expression you can use something like: `2nd wednesday of march 17:00` instead of the traditional crontab like expression, that is what I wanna say. Sorry if I did not explain myself very well in the answer. Please, try it – jccampanero Mar 17 '21 at 16:08
  • @jccampnrero, thanks for your reply. It didn’t work :( only it’s allowed to use unix cron jobs. – Jhony Chu Mar 17 '21 at 18:39
  • 1
    I am sorry to hear that @JhonyChu. I was sure about that. Please, see the relevant [documentation](https://cloud.google.com/sdk/gcloud/reference/scheduler/jobs/create/http) of the cloud command line, when they describe the `schedule` definition under `REQUIRED FLAGS`. They clearly indicate that both kind of expression are supported. Did you try to tdefine the expression from the Web console or the `gcloud` CLI? Maybe the Web console only allows you to define unix cron expressions and this second kind of expressions can only be used with the `gcloud` CLI. – jccampanero Mar 17 '21 at 18:59
  • Thanks for sharing! I will give it a shot :) and let you know! – Jhony Chu Mar 17 '21 at 19:42
  • You are welcome @JhonyChu. I hope you find the solution. Please, do not hesitate to contact me again as many times as you consider appropriate. – jccampanero Mar 17 '21 at 22:02