lxd: github.com/lxc/lxd/lxd/task Index | Files

package task

import "github.com/lxc/lxd/lxd/task"

Index

Package Files

func.go group.go schedule.go start.go task.go

Variables

var ErrSkip = fmt.Errorf("skip execution of task function")

ErrSkip is a special error that may be returned by a Schedule function to mean to skip a particular execution of the task function, and just wait the returned interval before re-evaluating.

var SkipFirst = func(every *every) { every.skipFirst = true }

SkipFirst is an option for the Every schedule that will make the schedule skip the very first invokation of the task function.

func Start Uses

func Start(f Func, schedule Schedule) (func(time.Duration) error, func())

Start a single task executing the given function with the given schedule.

This is a convenience around Group and it returns two functions that can be used to control the task. The first is a "stop" function trying to terminate the task gracefully within the given timeout and the second is a "reset" function to reset the task's state. See Group.Stop() and Group.Reset() for more details.

type EveryOption Uses

type EveryOption func(*every)

EveryOption captures a tweak that can be applied to the Every schedule.

type Func Uses

type Func func(context.Context)

Func captures the signature of a function executable by a Task.

When the given context is done, the function must gracefully terminate whatever logic it's executing.

type Group Uses

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

Group of tasks sharing the same lifecycle.

All tasks in a group will be started and stopped at the same time.

func (*Group) Add Uses

func (g *Group) Add(f Func, schedule Schedule) *Task

Add a new task to the group, returning its index.

func (*Group) Start Uses

func (g *Group) Start()

Start all the tasks in the group.

func (*Group) Stop Uses

func (g *Group) Stop(timeout time.Duration) error

Stop all tasks in the group.

This works by sending a cancellation signal to all tasks of the group and waiting for them to terminate.

If a task is idle (i.e. not executing its task function) it will terminate immediately.

If a task is busy executing its task function, the cancellation signal will propagate through the context passed to it, and the task will block waiting for the function to terminate.

In case the given timeout expires before all tasks complete, this method exits immediately and returns an error, otherwise it returns nil.

type Schedule Uses

type Schedule func() (time.Duration, error)

Schedule captures the signature of a schedule function.

It should return the amount of time to wait before triggering the next execution of a task function.

If it returns zero, the function does not get run at all.

If it returns a duration greater than zero, the task function gets run once immediately and then again after the specified amount of time. At that point the Task re-invokes the schedule function and repeats the same logic.

If ErrSkip is returned, the immediate execution of the task function gets skipped, and it will only be possibly executed after the returned interval.

If any other error is returned, the task won't execute the function, however if the returned interval is greater than zero it will re-try to run the schedule function after that amount of time.

func Daily Uses

func Daily(options ...EveryOption) Schedule

Daily is a convenience for creating a schedule that runs once a day.

func Every Uses

func Every(interval time.Duration, options ...EveryOption) Schedule

Every returns a Schedule that always returns the given time interval.

type Task Uses

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

Task executes a certain function periodically, according to a certain schedule.

func (*Task) Reset Uses

func (t *Task) Reset()

Reset the state of the task as if it had just been started.

This is handy if the schedule logic has changed, since the schedule function will be invoked immediately to determine whether and when to run the task function again.

Package task imports 6 packages (graph) and is imported by 15 packages. Updated 2019-07-19. Refresh now. Tools for package owners.