Cover by Dan Sanderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Chapter 13. Task Queues and Scheduled Tasks

The App Engine architecture is optimized for handling web requests, small amounts of work that run in a stateless environment with the intent of returning a response to the user as fast as possible. But many web applications have other kinds of work that need to get done, work that doesn’t fit in the fast response model. Instead of doing the work while the user waits, it’s often acceptable to record what work needs to get done, respond to the user right away, then do the work later, within seconds or minutes. The ability to make this trade-off is especially useful with scalable web applications that use a read-optimized datastore, since updating an element of data may require several related but time-consuming updates, and it may not be essential for those updates to happen right away.

Then there’s the work that needs to get done independently of user actions: fetching and caching fresh data from remote sources, sending daily status email messages, respawning health packs and enemies throughout the island. For this, it would be useful to configure a schedule of work that needs to be done on a regular basis, and that gets performed regardless of web traffic from users.

App Engine provides facilities for these categories of work: task queues and scheduled tasks. With task queues, a request handler invoked by a user request can enqueue a unit of work—a task—and return a response to the user and exit. App Engine executes enqueued tasks at a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required