Documentation ¶
Overview ¶
This code is based on work from the cron project
Source: https://github.com/robfig/cron Original author: Rob Figueiredo Licensed under the MIT License: https://opensource.org/licenses/MIT
This code is based on work from the cron project ¶
Source: https://github.com/robfig/cron Original author: Rob Figueiredo Licensed under the MIT License: https://opensource.org/licenses/MIT
This code is based on work from the goim project ¶
Source: https://github.com/Terry-Mao/goim/blob/master/pkg/time/timer.go Original author: Terry.Mao Licensed under the MIT License: https://opensource.org/licenses/MIT
Index ¶
- func NewEngine(maxWorkers, rate int, picker Picker) *engine
- func WithEngine(ec EngineCreator) *cronOption
- func WithHighLevel() *scheduleOption
- func WithID(id EntryID) *scheduleOption
- func WithJobWrapper(jobWrapper func(Schedule, Picker, Job) (Job, CancelHandler)) *scheduleOption
- func WithLocation(loc *time.Location) *cronOption
- func WithLowLevel() *scheduleOption
- func WithParser(sp ScheduleParser) *cronOption
- func WithPicker(pc PickerCreator) *cronOption
- type CancelHandler
- type ConstantDelaySchedule
- type Cron
- func (c *Cron) AddFunc(spec string, cmd func(), opt ...ScheduleOption) (EntryID, error)
- func (c *Cron) AddJob(spec string, cmd Job, opt ...ScheduleOption) (EntryID, error)
- func (c *Cron) Entry(id EntryID) *Entry
- func (c *Cron) Location() *time.Location
- func (c *Cron) Remove(id EntryID)
- func (c *Cron) Schedule(schedule Schedule, cmd Job, opt ...ScheduleOption) EntryID
- func (m *Cron) Start() error
- func (m *Cron) Stop() (context.Context, error)
- type CronOption
- type CronOptions
- type Engine
- type EngineCreator
- type Entry
- type EntryID
- type FuncJob
- type Job
- type JobLevel
- type JobLevelWrapper
- type JobPicker
- type LevelPicker
- type ParseOption
- type Parser
- type Picker
- type PickerCreator
- type Schedule
- type ScheduleOption
- type ScheduleOptions
- type ScheduleParser
- type SpecSchedule
- type Timer
- type TimerData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithEngine ¶
func WithEngine(ec EngineCreator) *cronOption
func WithHighLevel ¶
func WithHighLevel() *scheduleOption
func WithJobWrapper ¶
func WithJobWrapper(jobWrapper func(Schedule, Picker, Job) (Job, CancelHandler)) *scheduleOption
func WithLocation ¶
func WithLowLevel ¶
func WithLowLevel() *scheduleOption
func WithParser ¶
func WithParser(sp ScheduleParser) *cronOption
func WithPicker ¶
func WithPicker(pc PickerCreator) *cronOption
Types ¶
type CancelHandler ¶
type CancelHandler func()
type ConstantDelaySchedule ¶
func Every ¶
func Every(duration time.Duration) ConstantDelaySchedule
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
func NewCron ¶
func NewCron(opt ...CronOption) *Cron
func (*Cron) AddFunc ¶
func (c *Cron) AddFunc(spec string, cmd func(), opt ...ScheduleOption) (EntryID, error)
AddFunc adds a func to the Cron to be run on the given schedule. The spec is parsed using the time zone of this Cron instance as the default. An ID is returned that can be used to later remove it.
func (*Cron) AddJob ¶
AddJob adds a Job to the Cron to be run on the given schedule. The spec is parsed using the time zone of this Cron instance as the default. An ID is returned that can be used to later remove it.
type CronOption ¶
type CronOption interface {
// contains filtered or unexported methods
}
type CronOptions ¶
type CronOptions struct {
// contains filtered or unexported fields
}
type EngineCreator ¶
type JobLevel ¶
type JobLevel interface { Pick() <-chan Job Remove(*JobLevelWrapper) Add(*JobLevelWrapper) Redo(*JobLevelWrapper) }
type JobLevelWrapper ¶
type JobLevelWrapper struct {
// contains filtered or unexported fields
}
func (*JobLevelWrapper) Run ¶
func (w *JobLevelWrapper) Run()
type LevelPicker ¶
func NewLevelPicker ¶
func NewLevelPicker(loc *time.Location) *LevelPicker
func (*LevelPicker) Add ¶
func (lp *LevelPicker) Add(j Job, fn func()) error
func (*LevelPicker) Del ¶
func (lp *LevelPicker) Del(j Job)
func (*LevelPicker) Start ¶
func (lp *LevelPicker) Start() error
func (*LevelPicker) Stop ¶
func (lp *LevelPicker) Stop() error
type ParseOption ¶
type ParseOption int
Configuration options for creating a parser. Most options specify which fields should be included, while others enable features. If a field is not included the parser will assume a default value. These options do not change the order fields are parse in.
const ( Second ParseOption = 1 << iota // Seconds field, default 0 SecondOptional // Optional seconds field, default 0 Minute // Minutes field, default 0 Hour // Hours field, default 0 Dom // Day of month field, default * Month // Month field, default * Dow // Day of week field, default * DowOptional // Optional day of week field, default * Descriptor // Allow descriptors such as @monthly, @weekly, etc. )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
A custom Parser that can be configured.
func NewParser ¶
func NewParser(options ParseOption) Parser
NewParser creates a Parser with custom options.
It panics if more than one Optional is given, since it would be impossible to correctly infer which optional is provided or missing in general.
Examples
// Standard parser without descriptors specParser := NewParser(Minute | Hour | Dom | Month | Dow) sched, err := specParser.Parse("0 0 15 */3 *") // Same as above, just excludes time fields specParser := NewParser(Dom | Month | Dow) sched, err := specParser.Parse("15 */3 *") // Same as above, just makes Dow optional specParser := NewParser(Dom | Month | DowOptional) sched, err := specParser.Parse("15 */3")
type PickerCreator ¶
type PickerCreator func() JobPicker
type Schedule ¶
type Schedule interface { // Next returns the next activation time, later than the given time. // Next is invoked initially, and then each time the job is run. Next(time.Time) time.Time }
Schedule describes a job's duty cycle.
func ParseStandard ¶
ParseStandard returns a new crontab schedule representing the given standardSpec (https://en.wikipedia.org/wiki/Cron). It requires 5 entries representing: minute, hour, day of month, month and day of week, in that order. It returns a descriptive error if the spec is not valid.
It accepts
- Standard crontab specs, e.g. "* * * * ?"
- Descriptors, e.g. "@midnight", "@every 1h30m"
type ScheduleOption ¶
type ScheduleOption interface {
// contains filtered or unexported methods
}
type ScheduleOptions ¶
type ScheduleOptions struct {
// contains filtered or unexported fields
}
type ScheduleParser ¶
ScheduleParser is an interface for schedule spec parsers that return a Schedule
type SpecSchedule ¶
type SpecSchedule struct {
Second, Minute, Hour, Dom, Month, Dow uint64
// Override location for this schedule.
Location *time.Location
}
SpecSchedule specifies a duty cycle (to the second granularity), based on a traditional crontab specification. It is computed initially and stored as bit sets.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer timer.
func NewTimer ¶
NewTimer new a timer. A heap must be initialized before any of the heap operations can be used. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated. Its complexity is O(n) where n = h.Len().
func (*Timer) Add ¶
Add add the element x onto the heap. The complexity is O(log(n)) where n = h.Len().
type TimerData ¶
type TimerData struct {
// contains filtered or unexported fields
}
TimerData timer data.
func (*TimerData) ExpireString ¶
ExpireString expire string.