Documentation ¶
Index ¶
- Constants
- type Scheduler
- type Task
- type TaskConfig
- func (tc *TaskConfig) After(interval time.Duration) *TaskConfig
- func (tc *TaskConfig) At(hour, minute int) *TaskConfig
- func (tc *TaskConfig) Day() *TaskConfig
- func (tc *TaskConfig) Days() *TaskConfig
- func (tc *TaskConfig) Do(f TaskHandler, payload ...interface{}) *TaskConfig
- func (tc *TaskConfig) Friday() *TaskConfig
- func (tc *TaskConfig) From(from time.Time) *TaskConfig
- func (tc *TaskConfig) Hour() *TaskConfig
- func (tc *TaskConfig) Hours() *TaskConfig
- func (tc *TaskConfig) Millisecond() *TaskConfig
- func (tc *TaskConfig) Milliseconds() *TaskConfig
- func (tc *TaskConfig) Minute() *TaskConfig
- func (tc *TaskConfig) Minutes() *TaskConfig
- func (tc *TaskConfig) Monday() *TaskConfig
- func (tc *TaskConfig) OnBeforeStart(f TaskHandler) *TaskConfig
- func (tc *TaskConfig) OnError(f TaskErrorHandler) *TaskConfig
- func (tc *TaskConfig) OnFinish(f TaskHandler) *TaskConfig
- func (tc *TaskConfig) Saturday() *TaskConfig
- func (tc *TaskConfig) Second() *TaskConfig
- func (tc *TaskConfig) Seconds() *TaskConfig
- func (tc *TaskConfig) Sunday() *TaskConfig
- func (tc *TaskConfig) Thursday() *TaskConfig
- func (tc *TaskConfig) To(to time.Time) *TaskConfig
- func (tc *TaskConfig) Tuesday() *TaskConfig
- func (tc *TaskConfig) Wednesday() *TaskConfig
- func (tc *TaskConfig) Week() *TaskConfig
- func (tc *TaskConfig) Weeks() *TaskConfig
- type TaskErrorHandler
- type TaskHandler
Constants ¶
const DefaultPrecision = time.Millisecond * 100
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler is used to create and manage TaskConfig. Thread-safe.
Example:
s := NewScheduler(DefaultPrecision) s.Every(1).Seconds().Do(func(t *Task) error { return nil }) s.Every(2).Hours().Do(func(t *Task) error { return nil }) s.Every().Day().Do(func(t *Task) error { return nil }) s.Start()
func NewScheduler ¶
NewScheduler creates a new scheduler.
Smaller precision may add to CPU load with many taskConfigs running, due to periodical checks.
func (*Scheduler) Every ¶
func (s *Scheduler) Every(interval ...int) *TaskConfig
Every begins configuring a task. supply zero or one intervals. no intervals will be counted as 1
func (*Scheduler) Once ¶
func (s *Scheduler) Once() *TaskConfig
Once begins configuring a task. sets the task to run only once. use TaskConfig.After or TaskConfig.From to set the time.
type Task ¶
type Task struct { Payload interface{} Elapsed time.Duration // contains filtered or unexported fields }
Task is passed to task handlers and contains the payload
type TaskConfig ¶
type TaskConfig struct {
// contains filtered or unexported fields
}
func (*TaskConfig) After ¶
func (tc *TaskConfig) After(interval time.Duration) *TaskConfig
After starts the task after the specified duration. Short hand for From(time.Now().Add(interval))
func (*TaskConfig) At ¶
func (tc *TaskConfig) At(hour, minute int) *TaskConfig
At sets the time of day to run the task.
func (*TaskConfig) Do ¶
func (tc *TaskConfig) Do(f TaskHandler, payload ...interface{}) *TaskConfig
Do start the task with the supplied payload in a new goroutine.
func (*TaskConfig) Friday ¶
func (tc *TaskConfig) Friday() *TaskConfig
Friday sets the unit to weeks and only runs on Fridays.
func (*TaskConfig) From ¶
func (tc *TaskConfig) From(from time.Time) *TaskConfig
From sets the start time of the task.
func (*TaskConfig) Millisecond ¶ added in v0.0.15
func (tc *TaskConfig) Millisecond() *TaskConfig
Millisecond sets the interval to milliseconds.
func (*TaskConfig) Milliseconds ¶ added in v0.0.15
func (tc *TaskConfig) Milliseconds() *TaskConfig
Milliseconds is same as Millisecond.
func (*TaskConfig) Minute ¶
func (tc *TaskConfig) Minute() *TaskConfig
Minute sets the interval to minutes.
func (*TaskConfig) Monday ¶
func (tc *TaskConfig) Monday() *TaskConfig
Monday sets the unit to weeks and only runs on Mondays.
func (*TaskConfig) OnBeforeStart ¶ added in v0.0.15
func (tc *TaskConfig) OnBeforeStart(f TaskHandler) *TaskConfig
OnBeforeStart sets the handler to be called before the task starts.
func (*TaskConfig) OnError ¶ added in v0.0.15
func (tc *TaskConfig) OnError(f TaskErrorHandler) *TaskConfig
OnError sets the error handler for the task. Errors happening in tasks won't stop the task from running. Call Task.Stop to stop the task.
func (*TaskConfig) OnFinish ¶ added in v0.0.15
func (tc *TaskConfig) OnFinish(f TaskHandler) *TaskConfig
OnFinish sets the finish handler for the task.
func (*TaskConfig) Saturday ¶
func (tc *TaskConfig) Saturday() *TaskConfig
Saturday sets the unit to weeks and only runs on Saturdays.
func (*TaskConfig) Second ¶
func (tc *TaskConfig) Second() *TaskConfig
Second sets the interval to seconds.
func (*TaskConfig) Sunday ¶
func (tc *TaskConfig) Sunday() *TaskConfig
Sunday sets the unit to weeks and only runs on Sundays.
func (*TaskConfig) Thursday ¶
func (tc *TaskConfig) Thursday() *TaskConfig
Thursday sets the unit to weeks and only runs on Thursdays.
func (*TaskConfig) To ¶
func (tc *TaskConfig) To(to time.Time) *TaskConfig
To sets the end time of the task.
func (*TaskConfig) Tuesday ¶
func (tc *TaskConfig) Tuesday() *TaskConfig
Tuesday sets the unit to weeks and only runs on Tuesdays.
func (*TaskConfig) Wednesday ¶
func (tc *TaskConfig) Wednesday() *TaskConfig
Wednesday sets the unit to weeks and only runs on Wednesdays.