From 46176699e2b1e82c226e32a0678e1467a29fbb5a Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 14 Sep 2015 21:21:07 +0300 Subject: [PATCH] fix for scheduler multiple execution fixes #175 --- scheduler/scheduler.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 93abc0073..c00b9b5d4 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -46,22 +46,27 @@ func (s *Scheduler) Loop() { } s.Lock() a0 := s.queue[0] + //engine.Logger.Info(fmt.Sprintf("Scheduler qeue length: %v", len(s.qeue))) now := time.Now() - if a0.GetNextStartTime(now).Equal(now) || a0.GetNextStartTime(now).Before(now) { + start := a0.GetNextStartTime(now) + if start.Equal(now) || start.Before(now) { go a0.Execute() // if after execute the next start time is in the past then // do not add it to the queue - now = time.Now() - if !a0.GetNextStartTime(now).Before(now) { + now = time.Now().Add(time.Second) + start = a0.GetNextStartTime(now) + if !start.Before(now) { s.queue = append(s.queue, a0) s.queue = s.queue[1:] sort.Sort(s.queue) + } else { + s.queue = s.queue[1:] } s.Unlock() } else { s.Unlock() d := a0.GetNextStartTime(now).Sub(now) - // engine.Logger.Info(fmt.Sprintf("Timer set to wait for %v", d)) + //engine.Logger.Info(fmt.Sprintf("Timer set to wait for %v", d)) s.timer = time.NewTimer(d) select { case <-s.timer.C: