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 ¶
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 ¶
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.
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 ¶
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.