Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



The delay package

import "appengine/delay"

Introduction

Package delay provides a way to execute code outside the scope of a user request by using the taskqueue API.

To declare a function that may be executed later, call Func in a top-level assignment context, passing it an arbitrary string key and a function whose first argument is of type appengine.Context.

var laterFunc = delay.Func("key", myFunc)

It is also possible to use a function literal.

var laterFunc = delay.Func("key", func(c appengine.Context, x string) {
    // ...
})

To call a function, invoke its Call method.

laterFunc.Call(c, "something")

A function may be called any number of times. If the function has any return arguments, and the last one is of type error, the function may return a non-nil error to signal that the function should be retried.

The arguments to functions may be of any type that is encodable by the gob package. If an argument is of interface type, it is the client's responsibility to register with the gob package whatever concrete type may be passed for that argument; see http://golang.org/pkg/gob/#Register for details.

Any errors during initialization or execution of a function will be logged to the application logs. Error logs that occur during initialization will be associated with the request that invoked the Call method.

The state of a function invocation that has not yet successfully executed is preserved by combining the file name in which it is declared with the string key that was passed to the Func function. Updating an app with pending function invocations is safe as long as the relevant functions have the (filename, key) combination preserved.

The delay package uses the Task Queue API to create tasks that call the reserved application path "/_ah/queue/go/delay". This path must not be marked as "login: required" in app.yaml; it must be marked as "login: admin" or have no access restriction.

Index

type Function
func Func(key string, i interface{}) *Function
func (f *Function) Call(c appengine.Context, args ...interface{})
func (f *Function) Task(args ...interface{}) (*taskqueue.Task, error)

type Function

type Function struct {
    // contains filtered or unexported fields
}

Function represents a function that may have a delayed invocation.

func Func

func Func(key string, i interface{}) *Function

Func declares a new Function. The second argument must be a function with a first argument of type appengine.Context. This function must be called at program initialization time. That means it must be called in a global variable declaration or from an init function. This restriction is necessary because the instance that delays a function call may not be the one that executes it. Only the code executed at program initialization time is guaranteed to have been run by an instance before it receives a request.

func (*Function) Call

func (f *Function) Call(c appengine.Context, args ...interface{})

Call invokes a delayed function.

f.Call(c, ...)

is equivalent to

t, _ := f.Task(...)
taskqueue.Add(c, t, "")

func (*Function) Task

func (f *Function) Task(args ...interface{}) (*taskqueue.Task, error)

Task creates a Task that will invoke the function. Its parameters may be tweaked before adding it to a queue. Users should not modify the Path or Payload fields of the returned Task.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.