diff --git a/engine/stats.go b/engine/stats.go index 51c87c266..2e9ba38b2 100644 --- a/engine/stats.go +++ b/engine/stats.go @@ -75,9 +75,9 @@ func newQueueSaver(saveInterval time.Duration, sq *StatsQueue, adb AccountingSto } func (svr *queueSaver) stop() { + svr.sq.Save(svr.accountingDb) svr.ticker.Stop() svr.stopper <- true - svr.sq.Save(svr.accountingDb) } func NewStats(ratingDb RatingStorage, accountingDb AccountingStorage, saveInterval time.Duration) *Stats { @@ -120,10 +120,15 @@ func (s *Stats) AddQueue(cs *CdrStats, out *int) error { if s.queueSavers == nil { s.queueSavers = make(map[string]*queueSaver) } - if sq, exists := s.queues[cs.Id]; exists { + var sq *StatsQueue + var exists bool + if sq, exists = s.queues[cs.Id]; exists { sq.UpdateConf(cs) } else { - s.queues[cs.Id] = NewStatsQueue(cs) + sq = NewStatsQueue(cs) + s.queues[cs.Id] = sq + } + if _, exists = s.queueSavers[sq.GetId()]; !exists { s.setupQueueSaver(sq) } return nil