Building Google Cloud Platform Solutions
上QQ阅读APP看书,第一时间看更新

Push queues

In the push model, workers define one or more route handlers in a worker.yaml configuration file, much like those defined in app.yaml. This includes a URL and a script, along with any number of optional handler properties. When a new task is created that matches this handler, the task queue invokes the worker's handler through a network call. Depending on how the task is created, this will take the form of an HTTP POST or HTTP GET.

Push queues are ideal for operations that should execute on a per-task basis. This model works well for tasks that are resource intensive. Because each task is pushed individually, the push model works well for tasks that should be executed in parallel. The downside to this is that high volumes of tasks will require a large number of workers to process them.

To create a worker using the push queue model, first create a worker.yaml file specifying the service and at least one handler:

runtime: python27
api_version: 1
threadsafe: true
service: example-worker

handlers:
- url: /.*
script: main.app

This worker.yaml will then be deployed with a Python WSGI application (defined as app in main.py), similar to our earlier default application. The Python application will then be responsible for handling inbound requests, returning a 2XX HTTP status code for success, or any other code for failure. Should the response code signify a failure, the task queue will retry the task according to predefined backoff rules. A push queue retry logic as well as other properties can be customized for a push queue be defining named queues.