From 624aa2b3f271e876311a4fa9815a6d3cca4a1955 Mon Sep 17 00:00:00 2001 From: gezimbll Date: Tue, 7 May 2024 09:30:10 -0400 Subject: [PATCH] update threshold to set snooze time after actions --- engine/thresholds.go | 2 +- engine/thresholds_test.go | 34 ++++++++++++++++++++++++++++++++++ go.sum | 2 -- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/engine/thresholds.go b/engine/thresholds.go index 13f7dbbf2..638e73304 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -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 { diff --git a/engine/thresholds_test.go b/engine/thresholds_test.go index 97ccb847a..571e73f2a 100644 --- a/engine/thresholds_test.go +++ b/engine/thresholds_test.go @@ -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 + } + + } + +} diff --git a/go.sum b/go.sum index 1a0a04a9d..7ec724ec4 100644 --- a/go.sum +++ b/go.sum @@ -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=