mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
call stats stop on kill and better add queue
This commit is contained in:
@@ -48,6 +48,8 @@ func generalSignalHandler() {
|
||||
|
||||
sig := <-c
|
||||
engine.Logger.Info(fmt.Sprintf("Caught signal %v, shuting down cgr-engine\n", sig))
|
||||
var dummyInt int
|
||||
cdrStats.Stop(dummyInt, &dummyInt)
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
@@ -61,6 +63,8 @@ func stopRaterSignalHandler() {
|
||||
|
||||
engine.Logger.Info(fmt.Sprintf("Caught signal %v, unregistering from balancer\n", sig))
|
||||
unregisterFromBalancer()
|
||||
var dummyInt int
|
||||
cdrStats.Stop(dummyInt, &dummyInt)
|
||||
exitChan <- true
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -203,8 +208,6 @@ func (s *Stats) UpdateQueues(css []*CdrStats, out *int) error {
|
||||
|
||||
if saved, err := s.accountingDb.GetCdrStatsQueue(sq.GetId()); err == nil {
|
||||
sq.Load(saved)
|
||||
} else {
|
||||
Logger.Debug(fmt.Sprintf("XXXXXXXXXXX: %v", err))
|
||||
}
|
||||
s.setupQueueSaver(sq)
|
||||
}
|
||||
|
||||
@@ -88,14 +88,14 @@ func (sq *StatsQueue) UpdateConf(conf *CdrStats) {
|
||||
func (sq *StatsQueue) Save(adb AccountingStorage) {
|
||||
sq.mux.Lock()
|
||||
defer sq.mux.Unlock()
|
||||
//if sq.dirty {
|
||||
Logger.Debug(fmt.Sprintf("SAVED: %+v", sq))
|
||||
if err := adb.SetCdrStatsQueue(sq); err != nil {
|
||||
Logger.Err(fmt.Sprintf("Error saving cdr stats queue id %s: %v", sq.GetId(), err))
|
||||
return
|
||||
if sq.dirty {
|
||||
Logger.Debug(fmt.Sprintf("SAVED: %+v", sq))
|
||||
if err := adb.SetCdrStatsQueue(sq); err != nil {
|
||||
Logger.Err(fmt.Sprintf("Error saving cdr stats queue id %s: %v", sq.GetId(), err))
|
||||
return
|
||||
}
|
||||
sq.dirty = false
|
||||
}
|
||||
sq.dirty = false
|
||||
//}
|
||||
}
|
||||
|
||||
func (sq *StatsQueue) Load(saved *StatsQueue) {
|
||||
|
||||
Reference in New Issue
Block a user