taskqueue

package
v0.0.0-...-3291bb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2015 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

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 constructed 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

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTaskAlreadyAdded is the error returned by Add and AddMulti when a task has already been added with a particular name.
	ErrTaskAlreadyAdded = errors.New("taskqueue: task has already been added")
)

Functions

func Delete

func Delete(c context.Context, task *Task, queueName string) error

Delete deletes a task from a named queue.

func DeleteMulti

func DeleteMulti(c context.Context, tasks []*Task, queueName string) error

DeleteMulti deletes multiple tasks from a named queue. If a given task could not be deleted, an appengine.MultiError is returned.

func ModifyLease

func ModifyLease(c context.Context, task *Task, queueName string, leaseTime int) error

ModifyLease modifies the lease of a task. Used to request more processing time, or to abandon processing. leaseTime is in seconds and must not be negative.

func Purge

func Purge(c context.Context, queueName string) error

Purge removes all tasks from a queue.

Types

type QueueStatistics

type QueueStatistics struct {
	Tasks     int       // may be an approximation
	OldestETA time.Time // zero if there are no pending tasks

	Executed1Minute int     // tasks executed in the last minute
	InFlight        int     // tasks executing now
	EnforcedRate    float64 // requests per second
}

QueueStatistics represents statistics about a single task queue.

func QueueStats

func QueueStats(c context.Context, queueNames []string) ([]QueueStatistics, error)

QueueStats retrieves statistics about queues.

type RetryOptions

type RetryOptions struct {
	// Number of tries/leases after which the task fails permanently and is deleted.
	// If AgeLimit is also set, both limits must be exceeded for the task to fail permanently.
	RetryLimit int32

	// Maximum time allowed since the task's first try before the task fails permanently and is deleted (only for push tasks).
	// If RetryLimit is also set, both limits must be exceeded for the task to fail permanently.
	AgeLimit time.Duration

	// Minimum time between successive tries (only for push tasks).
	MinBackoff time.Duration

	// Maximum time between successive tries (only for push tasks).
	MaxBackoff time.Duration

	// Maximum number of times to double the interval between successive tries before the intervals increase linearly (only for push tasks).
	MaxDoublings int32

	// If MaxDoublings is zero, set ApplyZeroMaxDoublings to true to override the default non-zero value.
	// Otherwise a zero MaxDoublings is ignored and the default is used.
	ApplyZeroMaxDoublings bool
}

RetryOptions let you control whether to retry a task and the backoff intervals between tries.

type Task

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.
	// url.Values' Encode method 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 specifies the duration the task queue service must wait
	// before executing the task.
	// Either Delay or ETA may be set, but not both.
	Delay time.Duration

	// ETA specifies the earliest time a task may be executed (push queues)
	// or leased (pull queues).
	// Either Delay or ETA may be set, but not both.
	ETA time.Time

	// The number of times the task has been dispatched or leased.
	RetryCount int32

	// Tag for the task. Only used when Method is PULL.
	Tag string

	// Retry options for this task. May be nil.
	RetryOptions *RetryOptions
}

A Task represents a task to be executed.

func Add

func Add(c context.Context, task *Task, queueName string) (*Task, 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 AddMulti

func AddMulti(c context.Context, tasks []*Task, queueName string) ([]*Task, error)

AddMulti adds multiple tasks to a named queue. An empty queue name means that the default queue will be used. AddMulti returns a slice of equivalent tasks with defaults filled in, including setting each task's Name field to the chosen name if the original was empty. If a given task is badly formed or could not be added, an appengine.MultiError is returned.

func Lease

func Lease(c context.Context, maxTasks int, queueName string, leaseTime int) ([]*Task, error)

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

func LeaseByTag

func LeaseByTag(c context.Context, maxTasks int, queueName string, leaseTime int, tag string) ([]*Task, error)

LeaseByTag leases tasks from a queue, grouped by tag. If tag is empty, then the returned tasks are grouped by the tag of the task with earliest ETA. leaseTime is in seconds. The number of tasks fetched will be at most maxTasks.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL