Scheduling tasks with Cron

We have designed the shrink operation as an optional functionality triggered by users, but we could run it at a determined time interval for every user in order to lower the costs of Cloud Storage. App Engine supports the scheduled execution of jobs with the Cron service; every application has a limited number of Cron jobs available, depending on our billing plan. Cron jobs have the same restrictions as tasks in a task queue, so the request can last up to 10 minutes.

We first prepare a request handler that will implement the job:

class ShrinkCronJob(ShrinkHandler): def post(self): self.abort(405, headers=[('Allow', 'GET')]) def get(self): if 'X-AppEngine-Cron' not in self.request.headers: self.error(403) notes = Note.query().fetch() ...

Get Python for Google App Engine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.