save conf of cdrstat when we save stat queue

This commit is contained in:
RBarrabe
2016-06-07 17:36:20 +02:00
parent 5db43f3e70
commit cb54d7d981
2 changed files with 12 additions and 5 deletions

View File

@@ -55,10 +55,11 @@ type queueSaver struct {
stopper chan bool
save func(*queueSaver)
sq *StatsQueue
ratingDb RatingStorage
accountingDb AccountingStorage
}
func newQueueSaver(saveInterval time.Duration, sq *StatsQueue, adb AccountingStorage) *queueSaver {
func newQueueSaver(saveInterval time.Duration, sq *StatsQueue, rdb RatingStorage, adb AccountingStorage) *queueSaver {
svr := &queueSaver{
ticker: time.NewTicker(saveInterval),
stopper: make(chan bool),
@@ -69,7 +70,7 @@ func newQueueSaver(saveInterval time.Duration, sq *StatsQueue, adb AccountingSto
for {
select {
case <-svr.ticker.C:
sq.Save(adb)
sq.Save(rdb, adb)
case <-svr.stopper:
break
}
@@ -79,7 +80,7 @@ func newQueueSaver(saveInterval time.Duration, sq *StatsQueue, adb AccountingSto
}
func (svr *queueSaver) stop() {
svr.sq.Save(svr.accountingDb)
svr.sq.Save(svr.ratingDb, svr.accountingDb)
svr.ticker.Stop()
svr.stopper <- true
}
@@ -285,7 +286,7 @@ func (s *Stats) setupQueueSaver(sq *StatsQueue) {
si = s.defaultSaveInterval
}
if si > 0 {
s.queueSavers[sq.GetId()] = newQueueSaver(si, sq, s.accountingDb)
s.queueSavers[sq.GetId()] = newQueueSaver(si, sq, s.ratingDb, s.accountingDb)
}
}

View File

@@ -91,10 +91,16 @@ func (sq *StatsQueue) UpdateConf(conf *CdrStats) {
}
}
func (sq *StatsQueue) Save(adb AccountingStorage) {
func (sq *StatsQueue) Save(rdb RatingStorage, adb AccountingStorage) {
sq.mux.Lock()
defer sq.mux.Unlock()
if sq.dirty {
// save the conf
if err := rdb.SetCdrStats(sq.conf); err != nil {
utils.Logger.Err(fmt.Sprintf("Error saving cdr stats id %s: %v", sq.conf.Id, err))
return
}
if err := adb.SetCdrStatsQueue(sq); err != nil {
utils.Logger.Err(fmt.Sprintf("Error saving cdr stats queue id %s: %v", sq.GetId(), err))
return