JJ Geewax
JJ Geewax

Reputation: 10579

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"?

Upvotes: 4

Views: 3456

Answers (4)

mindlesstux
mindlesstux

Reputation: 308

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

Upvotes: 5

Nick Johnson
Nick Johnson

Reputation: 101149

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.

Upvotes: 4

John La Rooy
John La Rooy

Reputation: 304175

The docs say you can have 20 cron entries, so you can't have one for every hour of the day.

You could run your task every minute and check if it is the first minute of the hour - exit otherwise.

Upvotes: 1

goger
goger

Reputation: 593

Looking over the docs, I agree that your 24 cron entry idea is the only documented way that would work. Not ideal, but should work.

Upvotes: -1

Related Questions