Shudown method implemented in the scheduler

This commit is contained in:
DanB
2016-12-02 18:00:08 +01:00
parent c5cd0119d1
commit 1b22b53b34

View File

@@ -37,15 +37,20 @@ type Scheduler struct {
}
func NewScheduler(storage engine.RatingStorage) *Scheduler {
return &Scheduler{
s := &Scheduler{
restartLoop: make(chan bool),
storage: storage,
}
s.Reload()
return s
}
func (s *Scheduler) Loop() {
s.schedulerStarted = true
for {
if !s.schedulerStarted { // shutdown requested
break
}
for len(s.queue) == 0 { //hang here if empty
<-s.restartLoop
}
@@ -86,7 +91,7 @@ func (s *Scheduler) Loop() {
}
}
func (s *Scheduler) Reload(protect bool) {
func (s *Scheduler) Reload() {
s.loadActionPlans()
s.restart()
}
@@ -156,3 +161,11 @@ func (s *Scheduler) restart() {
func (s *Scheduler) GetQueue() engine.ActionTimingPriorityList {
return s.queue
}
func (s *Scheduler) Shutdown() error {
s.schedulerStarted = false // disable loop on next run
s.restartLoop <- true // cancel waiting tasks
if s.timer != nil {
s.timer.Stop()
}
}