English ▼
Skip to page content Skip to main navigation
e.g. "templates" or "datastore"

# The taskqueue package

## Introduction

Package taskqueue provides a client for App Engine's taskqueue service. Using this service, applications may perform work outside a user's request.

A Task may be constucted manually; alternatively, since the most common taskqueue operation is to add a single POST task, NewPOSTTask makes it easy.

    t := taskqueue.NewPOSTTask("/worker", url.Values{
        "key": {key},
    })
    taskqueue.Add(c, t, "") // add t to the default queue

## Functions

func Delete

  `func Delete(c appengine.Context, task *Task, queueName string) os.Error`

  Delete deletes a task from a named queue.

func LeaseTasks

  `func LeaseTasks(c appengine.Context, maxTasks int, queueName string, leaseTime int) ([]*Task, os.Error)`

  LeaseTasks leases tasks from a queue. leaseTime is in seconds. The number of tasks fetched will be at most maxTasks.

func Purge

  `func Purge(c appengine.Context, queueName string) os.Error`

  Purge removes all tasks from a queue.

## Types

type Task

A Task represents a task to be executed.

      type Task struct {
          // Path is the worker URL for the task.
          // If unset, it will default to /_ah/queue/<queue_name>.
          Path string

          // Payload is the data for the task.
          // This will be delivered as the HTTP request body.
          // It is only used when Method is POST, PUT or PULL.
          // http.EncodeQuery may be used to generate this for POST requests.
          Payload []byte

          // Additional HTTP headers to pass at the task's execution time.
          // To schedule the task to be run with an alternate app version
          // or backend, set the "Host" header.
          Header http.Header

          // Method is the HTTP method for the task ("GET", "POST", etc.),
          // or "PULL" if this is task is destined for a pull-based queue.
          // If empty, this defaults to "POST".
          Method string

          // A name for the task.
          // If empty, a name will be chosen.
          Name string

          // Delay is how far into the future this task should execute, in microseconds.
          Delay int64
      }

  func Add

    `func Add(c appengine.Context, task *Task, queueName string) (*Task, os.Error)`

    Add adds the task to a named queue. An empty queue name means that the default queue will be used. Add returns an equivalent Task with defaults filled in, including setting the task's Name field to the chosen name if the original was empty.

  func NewPOSTTask

    `func NewPOSTTask(path string, params url.Values) *Task`

    NewPOSTTask creates a Task that will POST to a path with the given form data.