mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
save conf of cdrstat when we save stat queue
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user