update threshold to set snooze time after actions

This commit is contained in:
gezimbll
2024-05-07 09:30:10 -04:00
committed by Dan Christian Bogos
parent d2b4a9ba81
commit 624aa2b3f2
3 changed files with 35 additions and 3 deletions

View File

@@ -185,6 +185,7 @@ func (t *Threshold) ProcessEvent(args *utils.CGREvent, dm *DataManager, fltrS *F
err = utils.ErrPartiallyExecuted
}
}
t.Snooze = time.Now().Add(t.tPrfl.MinSleep)
return
}
@@ -464,7 +465,6 @@ func (tS *ThresholdService) processEvent(tnt string, args *utils.CGREvent) (thre
}
continue
}
t.Snooze = time.Now().Add(t.tPrfl.MinSleep)
// recurrent threshold
*t.dirty = true // mark it to be saved
if tS.cgrcfg.ThresholdSCfg().StoreInterval == -1 {

View File

@@ -2358,3 +2358,37 @@ func TestThresholdsStoreThresholdCacheSetErr(t *testing.T) {
utils.Logger.SetLogLevel(0)
}
func TestThresholdSnoozeSleep(t *testing.T) {
th := &Threshold{
Tenant: "cgrates.org",
ID: "th_counter",
tPrfl: &ThresholdProfile{
MaxHits: -1,
MinHits: 1,
Blocker: true,
Weight: 30,
MinSleep: 3 * time.Second,
Async: true,
},
}
cfg := config.NewDefaultCGRConfig()
db := NewInternalDB(nil, nil, true, cfg.DataDbCfg().Items)
dm := NewDataManager(db, cfg.CacheCfg(), nil)
fs := NewFilterS(cfg, nil, dm)
var snoozeTime time.Time
for i, arg := range testThresholdArgs {
th.ProcessEvent(arg, dm, fs)
if i > 0 {
if !th.Snooze.Equal(snoozeTime) {
t.Error("expecte snooze to not change during sleep time")
}
} else {
snoozeTime = th.Snooze
}
}
}

2
go.sum
View File

@@ -68,8 +68,6 @@ github.com/cgrates/birpc v1.3.1-0.20211117095917-5b0ff29f3084 h1:YIEepjEOjeHaFre
github.com/cgrates/birpc v1.3.1-0.20211117095917-5b0ff29f3084/go.mod h1:z/PmNnDPqSQALedKJv5T8+eXIq6XHa9J0St1YsvAVns=
github.com/cgrates/fsock v0.0.0-20240322171959-35309017b3e0 h1:rnSM0tG6Cl8GXjyBQXw78WEaJolKfZqHTXkOCZh+w/k=
github.com/cgrates/fsock v0.0.0-20240322171959-35309017b3e0/go.mod h1:bKByLko2HF33K+PbiiToAgevrrbr96C+7Pp3HGS6oag=
github.com/cgrates/janusgo v0.0.0-20240430092034-1c3db3c74595 h1:f84+l8198ey/rM8oyYvBTFiUOf9fvQgAAGtMu6tUpLI=
github.com/cgrates/janusgo v0.0.0-20240430092034-1c3db3c74595/go.mod h1:XBQDDjrIn+RCS4PDApYjTWwdp51NbqYfUGAYtzSB5ag=
github.com/cgrates/janusgo v0.0.0-20240503152118-188a408d7e73 h1:7AYhvpegrSkY9tLGCQsZgNl8yTjL5CaQOTr3/kYlPek=
github.com/cgrates/janusgo v0.0.0-20240503152118-188a408d7e73/go.mod h1:XBQDDjrIn+RCS4PDApYjTWwdp51NbqYfUGAYtzSB5ag=
github.com/cgrates/kamevapi v0.0.0-20240307160311-26273f03eedf h1:GbMJzvtwdX1OCEmsqSts/cRCIcIMvo8AYtC2dQExWlg=