Small trend customisations

This commit is contained in:
DanB
2024-10-02 21:28:59 +02:00
parent 149ccc3eac
commit 28eb68241c
3 changed files with 18 additions and 7 deletions

View File

@@ -138,7 +138,6 @@ func TestTrendCleanUp(t *testing.T) {
t4 := now.Add(2 * time.Second)
t5 := now.Add(time.Minute)
trend := &Trend{
tMux: new(sync.RWMutex),
Tenant: "cgrates.org",
ID: "TestTrendCleanUp",

View File

@@ -124,7 +124,8 @@ func (tS *TrendS) computeTrend(tP *TrendProfile) {
mWt.TrendLabel = utils.NotAvailable
continue
}
if mWt.TrendGrowth, err = trend.getTrendGrowth(mID, mWt.Value, tP.CorrelationType, tS.cgrcfg.GeneralCfg().RoundingDecimals); err != nil {
if mWt.TrendGrowth, err = trend.getTrendGrowth(mID, mWt.Value, tP.CorrelationType,
tS.cgrcfg.GeneralCfg().RoundingDecimals); err != nil {
mWt.TrendLabel = utils.NotAvailable
} else {
mWt.TrendLabel = trend.getTrendLabel(mWt.TrendGrowth, tP.Tolerance)
@@ -141,13 +142,24 @@ func (tS *TrendS) computeTrend(tP *TrendProfile) {
}
func (tS *TrendS) StartScheduling() {
// StartCron will activates the Cron, together with all scheduled Trend queries
func (tS *TrendS) StartCron() {
tS.crn.Start()
}
func (tS *TrendS) StopScheduling() {
// StopCron will shutdown the Cron tasks
func (tS *TrendS) StopCron() {
ctx := tS.crn.Stop()
<-ctx.Done()
select {
case <-ctx.Done():
return
case <-time.After(tS.cgrcfg.CoreSCfg().ShutdownTimeout):
utils.Logger.Warning(
fmt.Sprintf(
"<%s> timeout waiting for Cron to finish",
utils.TrendS))
}
}
// scheduleTrendQueries will schedule/re-schedule specific trend queries

View File

@@ -83,7 +83,7 @@ func (trs *TrendService) Start() error {
trs.Lock()
defer trs.Unlock()
trs.trs = engine.NewTrendS(dm, trs.connMgr, filterS, trs.cfg)
trs.trs.StartScheduling()
trs.trs.StartCron()
srv, err := engine.NewService(v1.NewTrendSv1(trs.trs))
if err != nil {
return err
@@ -105,7 +105,7 @@ func (tr *TrendService) Shutdown() (err error) {
defer tr.srvDep[utils.DataDB].Done()
tr.Lock()
defer tr.Unlock()
tr.trs.StopScheduling()
tr.trs.StopCron()
<-tr.connChan
return
}