Project description

# appenginetaskutilsThis is the repo for the appengine task utils library. It generates the appenginetaskutils package

## Install

Use the python package for this library. You can find the package online [here](https://pypi.python.org/pypi/appenginetaskutils).

Change to your Python App Engine project's root folder and do the following:

> pip install appenginetaskutils --target lib

Or add it to your requirements.txt. You'll also need to set up vendoring, see [app engine vendoring instructions here](https://cloud.google.com/appengine/docs/python/tools/using-libraries-python-27).

## @task

The most basic element of the taskutils library is task(). This decorator function is designed to be used as a replacement for [deferred](https://cloud.google.com/appengine/articles/deferred).

### Configuring @task

When using deferred you have a builtin to configure in app.yaml to make it work. For taskutils.task, you need to add the following to your app.yaml and/or \<servicename\>.yaml file:

handlers: - url: /_ah/task/.* script: taskutils.app login: admin

This rule creates a generic handler for task to defer work to background push tasks.

Add it at the top of the list (to make sure other rules don't override it).

### Importing task

You can import task into your modules like this:

from taskutils import task

### Using task as a decorator

You can take any function and make it run in a separate task, like this:

@task def myfunction(): ... do stuff ...

Just call the function normally, eg:

myfunction()

You can use @task on any function, including nested functions, recursive functions, recursive nested functions, the sky is the limit. This is possible because of use of [yccloudpickle](https://medium.com/the-infinite-machine/python-function-serialisation-with-yccloudpickle-b2ff6b2ad5da#.zei3n0ibu) as the underlying serialisation library.

Details of the arguments allowed to Tasks are available [here](https://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.taskqueue), under **class google.appengine.api.taskqueue.Task(payload=None, \*\*kwargs)**. The task decorator supports a couple of extra ones, detailed below.

If you'd like access to headers in your function (a dictionary of headers passed to your task, it's a web request after all), set includeheaders=True in your call to @task. You'll also need to accept the headers argument in your function.