tasks

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package tasks provides functions for scheduling periodic tasks (e.g. background jobs).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx *app.Context, handler app.Handler) error

Execute runs the given handler in a task context. If the handler fails with a panic, it will be returned in the error return value.

func Run

func Run(ctx *app.Context, name string) (bool, error)

Run starts the given task identifier by it's name, unless it has been previously registered with Options which prevent from running it right now (e.g. it was registered with MaxInstances = 2 and there are already 2 instances running). The first return argument indicates if the task was executed, while the second includes any errors which happened while running the task.

func RunHandler

func RunHandler(ctx *app.Context, handler app.Handler) (bool, error)

RunHandler starts the given task identifier by it's handler. The same restrictions in Run() apply to this function. Return values are the same as Run().

Types

type Options

type Options struct {
	// Name indicates the task name, used for checking the number
	// of instances running. If the task name is not provided, it's
	// derived from the function. Two tasks with the same name are
	// considered as equal, even if their functions are different.
	Name string
	// MaxInstances indicates the maximum number of instances of
	// this function that can be simultaneously running. If zero,
	// there is no limit.
	MaxInstances int
}

Options are used to specify task options when registering them.

type Task

type Task struct {
	App      *app.App
	Handler  app.Handler
	Interval time.Duration
	Options  *Options
	// contains filtered or unexported fields
}

Task represent a scheduled task.

func Register

func Register(m *app.App, task app.Handler, opts *Options) *Task

Register registers a new task that might be run with Run, but without scheduling it. If there was previously another task registered with the same name, it will panic (use Task.Delete previously to remove it).

func Schedule

func Schedule(m *app.App, task app.Handler, opts *Options, interval time.Duration, onListen bool) *Task

Schedule registers and schedules a task to be run at the given interval. If interval is 0, the task is only registered, but not scheduled. The onListen argument indicates if the task should also run (in its own goroutine) as soon as the app starts listening rather than waiting until interval for the first run. Note that on App Engine, the task will be started when the first cron request comes in (these are usually scheduled to run once a minute).

Schedule returns a Task instance, which might be used to stop, resume or delete a it.

func (*Task) Delete

func (t *Task) Delete()

Delete stops the task by calling t.Stop() and then removes it from the internal task register.

func (*Task) Name

func (t *Task) Name() string

Name returns the task name.

func (*Task) Resume

func (t *Task) Resume(now bool)

func (*Task) Stop

func (t *Task) Stop()

Stop de-schedules the task. After stopping the task, it won't be started again but if it's currently running, it will be completed.

Jump to

Keyboard shortcuts

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