Documentation ¶
Index ¶
- type ChanJob
- type Schedulable
- type SchedulableFunc
- type Scheduler
- func (this *Scheduler) Add(name, interval string, s Schedulable) (err error)
- func (this *Scheduler) AddFunc(name, interval string, f func()) (err error)
- func (this *Scheduler) LockJob(name string) (locked bool)
- func (this *Scheduler) Remove(name string)
- func (this *Scheduler) RunJobAsync(name string)
- func (this *Scheduler) RunJobSync(name string)
- func (this *Scheduler) Start() (self *Scheduler)
- func (this *Scheduler) Stop()
- func (this *Scheduler) UnlockJob(name string)
- func (this *Scheduler) ValidInterval(in string) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChanJob ¶
type ChanJob struct { Name string // name of job (will be sent in StartC) StartC chan *ChanJob // chan scheduler uses to notify job should start StopC chan struct{} // chan job uses to notify that it is done CloseStart bool // true if we Close StartC CloseStop bool // true if we Close StopC // contains filtered or unexported fields }
Adapt Schedulable to provide notifications to a chan
func (*ChanJob) OnSchedule ¶
func (this *ChanJob) OnSchedule()
Invoked by Scheduler to run this periodically
implement Schedulable
type Schedulable ¶
type Schedulable interface {
OnSchedule()
}
implement this with whatever you want scheduler to run
type SchedulableFunc ¶
type SchedulableFunc func()
a func that is schedulable
func (SchedulableFunc) OnSchedule ¶
func (this SchedulableFunc) OnSchedule()
type Scheduler ¶
type Scheduler struct { Min time.Duration // minimum interval allowed Max time.Duration // maximum interval allowed Init int // max allowed concurrent initializations, or -1 // contains filtered or unexported fields }
Use this to schedule jobs
Manages job scheduling so that each job is unique by name.
Prevents each job from running at the same time as itself.
Prevents scheduling intervals that are too long or too short ¶
Randomizes interval to spread out the load.
Performs early initialization of jobs, as directed.
func (*Scheduler) Add ¶
func (this *Scheduler) Add(name, interval string, s Schedulable) (err error)
Schedule or reschedule a job
func (*Scheduler) LockJob ¶
prevent the scheduler from running the job, returning true if exclusive access was achieved
func (*Scheduler) Remove ¶
Cancel a job
Note: if you Remove, then Add the same named job, you might run the risk of running the same job concurrently. It is better in that case to just use Add.
func (*Scheduler) RunJobAsync ¶
start the job right now in its own goroutine
func (*Scheduler) RunJobSync ¶
run the job right now in the current goroutine
func (*Scheduler) ValidInterval ¶
validate and randomize interval