From be59d92ee4290104b02a5171ea42c47e4d1e4f20 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 30 Jun 2015 14:04:46 +0300 Subject: [PATCH] reverted to good add queue version --- engine/stats.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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