Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBackoff = errors.Errorf("skip execution of task function")
ErrBackoff is a special error that may be returned by a Schedule function to mean backoff the interval, before re-evaluating the interval of the next execution.
var ErrSkip = errors.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 ErrTerminate = errors.Errorf("terminate the task")
ErrTerminate is a special error that may be returned by a task function to terminate the task.
var Linear = func(backoff BackoffOptions) { backoff.SetBackoff(func(n int, t time.Duration) time.Duration { return t * time.Duration(n) }) }
Linear describes a backoff function that grows linearly with time.
var SkipFirst = func(every EveryOptions) { every.SetSkipFirst(true) }
SkipFirst is an option for the Every schedule that will make the schedule skip the very first invocation 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 BackoffFunc ¶
BackoffFunc is a type that represents a way to describe what the interval time should be for each backoff request. The amount is used to say how many iterations have occurred since the backoff was requested.
type BackoffOption ¶
type BackoffOption func(BackoffOptions)
BackoffOption captures a tweak that can be applied to the Backoff schedule.
type BackoffOptions ¶
type BackoffOptions interface {
SetBackoff(BackoffFunc)
}
BackoffOptions represents a way to set optional values to a backoff option. The BackoffOptions shows what options are available to change.
type Clock ¶
type Clock interface {
// After waits for the duration to elapse and then sends the current time
// on the returned channel.
// It is equivalent to NewTimer(d).C.
// The underlying Timer is not recovered by the garbage collector
// until the timer fires. If efficiency is a concern, use NewTimer
// instead and call Timer.Stop if the timer is no longer needed.
After(d time.Duration) <-chan time.Time
}
Clock represents the passage of time in a way that can be faked out for tests.
type EveryOption ¶
type EveryOption func(EveryOptions)
EveryOption captures a tweak that can be applied to the Every schedule.
type EveryOptions ¶
type EveryOptions interface {
SetSkipFirst(bool)
}
EveryOptions represents a way to set optional values to a every option. The EveryOptions shows what options are available to change.
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 Backoff ¶
func Backoff(interval time.Duration, options ...BackoffOption) Schedule
Backoff returns a Schedule that will attempt to backoff if there is a error passed.
func Daily ¶
func Daily(options ...EveryOption) Schedule
Daily is a convenience for creating a schedule that runs once a day.