Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a task every hour on the hour with App Engine's cron API

I need to run a task every hour on the hour (00:00, 01:00, 02:00, ..., 23:00) every day of the week, but can't seem to find an example in App Engine's docs of how to do this.

There is an example of running at ask every hour, but this doesn't fit because the "start" of that hour depends on when you deploy the application. That is, if I deploy at 4:37 PM, the cron scripts will get executed at 5:37, 6:37, ... instead of 5:00, 6:00, ...

So far the only way that looks like it would work is to have 24 different cron entries, one for the specific hour of each day set to run each day at that specific time.

Does anyone know of anything that would let me use a schedule like "every hour at :00" or even "every day 00:00, 01:00, ... 23:00"?

like image 726
JJ Geewax Avatar asked Jan 23 '23 03:01

JJ Geewax


2 Answers

You could do this, and give up the exactly on the hour, but it will be close...

(Example came from a app I was debuging)

cron:
- description: Description of what you want done...
  url: /script/path/goes/here
  schedule: every 60 minutes synchronized
  timezone: America/New_York

Below is a screenshot of the logs, the app gets no traffic right now, 99% of those entries are all the cron entry.

enter image description here

--- edit ---

Just re-read the docs as well and maybe this might be better,

  schedule: every 60 minutes from 00:00 to 23:59
like image 101
mindlesstux Avatar answered Feb 11 '23 08:02

mindlesstux


Unfortunately, the cron syntax doesn't let you specify the time for intervals less than a day. What you can do, however, is use the Task Queue for this. Either:

  1. Have a single task queue entry that, when it runs, enqueues a new task with the 'countdown' set to the number of seconds until the next time you want to run.
  2. Have a daily cron job that enqueues 24 hourly taskqueue entries at each of the times you want it to run.
like image 26
Nick Johnson Avatar answered Feb 11 '23 08:02

Nick Johnson