Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Python for Google App Engine
  • Toc
  • feedback
Python for Google App Engine

Python for Google App Engine

By : Pippi
4.1 (10)
close
Python for Google App Engine

Python for Google App Engine

4.1 (10)
By: Pippi

Overview of this book

If you are a Python developer, whether you have experience in web applications development or not, and want to rapidly deploy a scalable backend service or a modern web application on Google App Engine, then this book is for you.
Table of Contents (10 chapters)
close
9
Index

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()
        for note in notes:
            self._shrink_note(note)

We derive the ShrinkCronJob class from the ShrinkHandler class to inherit the _shrink_note() method...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist download font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete