gae: go.chromium.org/gae/service/taskqueue Index | Files

package taskqueue

import "go.chromium.org/gae/service/taskqueue"

Index

Package Files

context.go errors.go headers.go interface.go raw_interface.go task.go testable.go types.go

Variables

var ErrTaskAlreadyAdded = taskqueue.ErrTaskAlreadyAdded

ErrTaskAlreadyAdded is the error returned when a named task is added to a task queue more than once.

func Add Uses

func Add(c context.Context, queueName string, tasks ...*Task) error

Add adds the specified task(s) to the specified task queue.

If only one task is provided its error will be returned directly. If more than one task is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the task at that index.

If the number of tasks is beyond the limits of the underlying implementation, splits the batch into multiple ones.

func AddRawFilters Uses

func AddRawFilters(c context.Context, filts ...RawFilter) context.Context

AddRawFilters adds RawInterface filters to the context.

func Delete Uses

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

Delete deletes a task from the task queue.

If only one task is provided its error will be returned directly. If more than one task is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the task at that index.

If the number of tasks is beyond the limits of the underlying implementation, splits the batch into multiple ones.

func ModifyLease Uses

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

ModifyLease modifies the lease of a task.

Used to request more processing time, or to abandon processing. leaseTime has seconds precision and must not be negative.

On success, modifies task's ETA field in-place with updated lease expiration time.

func Purge Uses

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

Purge purges all tasks form the named queue.

func SetRaw Uses

func SetRaw(c context.Context, tq RawInterface) context.Context

SetRaw sets the current RawInterface object in the context. Useful for testing with a quick mock. This is just a shorthand SetRawFactory invocation to SetRaw a RawFactory which always returns the same object.

func SetRawFactory Uses

func SetRawFactory(c context.Context, tqf RawFactory) context.Context

SetRawFactory sets the function to produce RawInterface instances, as returned by the GetRaw method.

type AnonymousQueueData Uses

type AnonymousQueueData map[string][]*Task

AnonymousQueueData is {queueName: [*TQTask]}

type Constraints Uses

type Constraints struct {
    // MaxAddSize is the maximum number of tasks that can be added to a queue in
    // a single Add call.
    MaxAddSize int
    // MaxDeleteSize is the maximum number of tasks that can be deleted from
    // a queue in a single Delete call.
    MaxDeleteSize int
}

Constraints is the set of implementation-specific task queue constraints.

type QueueData Uses

type QueueData map[string]map[string]*Task

QueueData is {queueName: {taskName: *TQTask}}

type RawCB Uses

type RawCB func(index int, err error)

RawCB is a simple callback for RawInterface.DeleteMulti, getting the error for the attempted deletion.

type RawFactory Uses

type RawFactory func(c context.Context) RawInterface

RawFactory is the function signature for RawFactory methods compatible with SetRawFactory.

type RawFilter Uses

type RawFilter func(context.Context, RawInterface) RawInterface

RawFilter is the function signature for a RawFilter TQ implementation. It gets the current TQ implementation, and returns a new TQ implementation backed by the one passed in.

type RawInterface Uses

type RawInterface interface {
    // AddMulti adds multiple tasks to the given queue, calling cb for each item.
    //
    // The task passed to the callback function will have all the default values
    // filled in, and will have the Name field populated, if the input task was
    // anonymous (e.g. the Name field was blank).
    AddMulti(tasks []*Task, queueName string, cb RawTaskCB) error
    DeleteMulti(tasks []*Task, queueName string, cb RawCB) error

    Lease(maxTasks int, queueName string, leaseTime time.Duration) ([]*Task, error)
    LeaseByTag(maxTasks int, queueName string, leaseTime time.Duration, tag string) ([]*Task, error)
    ModifyLease(task *Task, queueName string, leaseTime time.Duration) error

    Purge(queueName string) error

    Stats(queueNames []string, cb RawStatsCB) error

    Constraints() Constraints

    GetTestable() Testable
}

RawInterface is the full interface to the Task Queue service.

func Raw Uses

func Raw(c context.Context) RawInterface

Raw gets the RawInterface implementation from context.

type RawStatsCB Uses

type RawStatsCB func(*Statistics, error)

RawStatsCB is the callback for RawInterface.Stats. It takes the statistics object, as well as an error (e.g. in case the queue doesn't exist).

type RawTaskCB Uses

type RawTaskCB func(*Task, error)

RawTaskCB is the callback for RawInterface.AddMulti, getting the added task and an error.

type RequestHeaders Uses

type RequestHeaders taskqueue.RequestHeaders

RequestHeaders are the special HTTP request headers available to push task HTTP request handlers.

func ParseRequestHeaders Uses

func ParseRequestHeaders(h http.Header) *RequestHeaders

ParseRequestHeaders parses the special HTTP request headers available to push task request handlers. This function silently ignores values of the wrong format.

type RetryOptions Uses

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 Statistics Uses

type Statistics 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
}

Statistics represents statistics about a single task queue.

func Stats Uses

func Stats(c context.Context, queueNames ...string) ([]Statistics, error)

Stats returns Statistics instances for each of the named task queues.

If only one task is provided its error will be returned directly. If more than one task is provided, an errors.MultiError will be returned in the event of an error, with a given error index corresponding to the error encountered when processing the task at that index.

type Task Uses

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
}

Task represents a taskqueue task to be executed.

func Lease Uses

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

Lease leases tasks from a queue.

leaseTime has seconds precision. The number of tasks fetched will be at most maxTasks.

func LeaseByTag Uses

func LeaseByTag(c context.Context, maxTasks int, queueName string, leaseTime time.Duration, 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 has seconds precision. The number of tasks fetched will be at most maxTasks.

func NewPOSTTask Uses

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

NewPOSTTask creates a Task that will POST to a path with URL-encoded values.

func (*Task) Duplicate Uses

func (t *Task) Duplicate() *Task

Duplicate returns a deep copy of this Task.

type Testable Uses

type Testable interface {
    CreateQueue(queueName string)
    CreatePullQueue(queueName string)
    GetScheduledTasks() QueueData
    GetTombstonedTasks() QueueData
    GetTransactionTasks() AnonymousQueueData
    ResetTasks()
}

Testable is the testable interface for fake taskqueue implementations

func GetTestable Uses

func GetTestable(c context.Context) Testable

GetTestable returns a Testable for the current task queue service in c, or nil if it does not offer one.

Package taskqueue imports 7 packages (graph) and is imported by 37 packages. Updated 2018-09-06. Refresh now. Tools for package owners.