Documentation ¶
Index ¶
Constants ¶
This section is empty.
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.
Functions ¶
func Start ¶
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.
Types ¶
type EveryOption ¶
type EveryOption func(*every)
EveryOption captures a tweak that can be applied to the Every schedule.
type Func ¶
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 ¶
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) Stop ¶
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 ¶
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 ¶
func Daily(options ...EveryOption) Schedule
Daily is a convenience for creating a schedule that runs once a day.
func Every ¶
func Every(interval time.Duration, options ...EveryOption) Schedule
Every returns a Schedule that always returns the given time interval.
func Hourly ¶
func Hourly(options ...EveryOption) Schedule
Hourly is a convenience for creating a schedule that runs once an hour.