diff --git a/data/storage/mysql/create_tariffplan_tables.sql b/data/storage/mysql/create_tariffplan_tables.sql index 9c898e42f..9b3aced87 100644 --- a/data/storage/mysql/create_tariffplan_tables.sql +++ b/data/storage/mysql/create_tariffplan_tables.sql @@ -198,7 +198,7 @@ CREATE TABLE `tp_action_triggers` ( `threshold_type` char(12) NOT NULL, `threshold_value` DECIMAL(20,4) NOT NULL, `recurrent` BOOLEAN NOT NULL, - `min_sleep` BIGINT NOT NULL, + `min_sleep` varchar(16) NOT NULL, `balance_destination_tag` varchar(64) NOT NULL, `balance_weight` DECIMAL(8,2) NOT NULL, `balance_expiry_time` varchar(24) NOT NULL, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index 7832146ed..283d3df7d 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -185,7 +185,7 @@ CREATE TABLE tp_action_triggers ( threshold_type char(12) NOT NULL, threshold_value NUMERIC(20,4) NOT NULL, recurrent BOOLEAN NOT NULL, - min_sleep BIGINT NOT NULL, + min_sleep VARCHAR(16) NOT NULL, balance_destination_tag VARCHAR(64) NOT NULL, balance_weight NUMERIC(8,2) NOT NULL, balance_expiry_time VARCHAR(24) NOT NULL, diff --git a/engine/loader_db.go b/engine/loader_db.go index c8a2a558c..523544f7a 100644 --- a/engine/loader_db.go +++ b/engine/loader_db.go @@ -654,12 +654,16 @@ func (dbr *DbReader) LoadActionTriggers() (err error) { if id == "" { id = utils.GenUUID() } + minSleep, err := utils.ParseDurationWithSecs(apiAtr.MinSleep) + if err != nil { + return err + } atrs[idx] = &ActionTrigger{ Id: id, ThresholdType: apiAtr.ThresholdType, ThresholdValue: apiAtr.ThresholdValue, Recurrent: apiAtr.Recurrent, - MinSleep: apiAtr.MinSleep, + MinSleep: minSleep, BalanceId: apiAtr.BalanceId, BalanceType: apiAtr.BalanceType, BalanceDirection: apiAtr.BalanceDirection, diff --git a/engine/models.go b/engine/models.go index 8c459822e..ea0a68bbf 100644 --- a/engine/models.go +++ b/engine/models.go @@ -163,7 +163,7 @@ type TpActionTrigger struct { ThresholdType string ThresholdValue float64 Recurrent bool - MinSleep int64 + MinSleep string BalanceTag string BalanceType string BalanceDirection string diff --git a/engine/storage_sql.go b/engine/storage_sql.go index bff8d430b..668cb40d4 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -620,7 +620,7 @@ func (self *SQLStorage) SetTPActionTriggers(tpid string, ats map[string][]*utils ThresholdType: at.ThresholdType, ThresholdValue: at.ThresholdValue, Recurrent: at.Recurrent, - MinSleep: int64(at.MinSleep), + MinSleep: at.MinSleep, BalanceTag: at.BalanceId, BalanceType: at.BalanceType, BalanceDirection: at.BalanceDirection, @@ -1447,7 +1447,7 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti ThresholdType: tpAt.ThresholdType, ThresholdValue: tpAt.ThresholdValue, Recurrent: tpAt.Recurrent, - MinSleep: time.Duration(tpAt.MinSleep), + MinSleep: tpAt.MinSleep, BalanceId: tpAt.BalanceTag, BalanceType: tpAt.BalanceType, BalanceDirection: tpAt.BalanceDirection, diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 082496639..bcb930ddc 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "log" "strconv" - "time" "github.com/cgrates/cgrates/utils" ) @@ -509,11 +508,6 @@ func (self *TPCSVImporter) importActionTriggers(fn string) error { log.Printf("Ignoring line %d, warning: <%s>", lineNr, err.Error()) continue } - minSleep, err := time.ParseDuration(record[ATRIGCSVIDX_MIN_SLEEP]) - if err != nil && record[ATRIGCSVIDX_MIN_SLEEP] != "" { - log.Printf("Ignoring line %d, warning: <%s>", lineNr, err.Error()) - continue - } balanceWeight, err := strconv.ParseFloat(record[ATRIGCSVIDX_BAL_WEIGHT], 64) if err != nil && record[ATRIGCSVIDX_BAL_WEIGHT] != "" { if self.Verbose { @@ -540,7 +534,7 @@ func (self *TPCSVImporter) importActionTriggers(fn string) error { ThresholdType: thresholdType, ThresholdValue: threshold, Recurrent: recurrent, - MinSleep: minSleep, + MinSleep: record[ATRIGCSVIDX_MIN_SLEEP], BalanceId: balanceId, BalanceType: balanceType, BalanceDirection: direction, diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 44f534300..d175b3dd7 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -523,7 +523,7 @@ type TPActionTriggers struct { func (self *TPActionTriggers) AsExportSlice() [][]string { retSlice := make([][]string, len(self.ActionTriggers)) for idx, at := range self.ActionTriggers { - retSlice[idx] = []string{self.ActionTriggersId, at.ThresholdType, strconv.FormatFloat(at.ThresholdValue, 'f', -1, 64), strconv.FormatBool(at.Recurrent), strconv.FormatFloat(at.MinSleep.Seconds(), 'f', -1, 64), + retSlice[idx] = []string{self.ActionTriggersId, at.ThresholdType, strconv.FormatFloat(at.ThresholdValue, 'f', -1, 64), strconv.FormatBool(at.Recurrent), at.MinSleep, at.BalanceId, at.BalanceType, at.BalanceDirection, at.BalanceCategory, at.BalanceDestinationId, at.BalanceRatingSubject, at.BalanceSharedGroup, at.BalanceExpirationDate, at.BalanceTimingTags, strconv.FormatFloat(at.BalanceWeight, 'f', -1, 64), strconv.Itoa(at.MinQueuedItems), at.ActionsId, strconv.FormatFloat(at.Weight, 'f', -1, 64)} } @@ -532,23 +532,23 @@ func (self *TPActionTriggers) AsExportSlice() [][]string { type TPActionTrigger struct { Id string - ThresholdType string // This threshold type - ThresholdValue float64 // Threshold - Recurrent bool // reset executed flag each run - MinSleep time.Duration // Minimum duration between two executions in case of recurrent triggers - BalanceId string // The id of the balance in the account - BalanceType string // Type of balance this trigger monitors - BalanceDirection string // Traffic direction - BalanceDestinationId string // filter for balance - BalanceWeight float64 // filter for balance - BalanceExpirationDate string // filter for balance - BalanceTimingTags string // filter for balance - BalanceRatingSubject string // filter for balance - BalanceCategory string // filter for balance - BalanceSharedGroup string // filter for balance - MinQueuedItems int // Trigger actions only if this number is hit (stats only) - ActionsId string // Actions which will execute on threshold reached - Weight float64 // weight + ThresholdType string // This threshold type + ThresholdValue float64 // Threshold + Recurrent bool // reset executed flag each run + MinSleep string // Minimum duration between two executions in case of recurrent triggers + BalanceId string // The id of the balance in the account + BalanceType string // Type of balance this trigger monitors + BalanceDirection string // Traffic direction + BalanceDestinationId string // filter for balance + BalanceWeight float64 // filter for balance + BalanceExpirationDate string // filter for balance + BalanceTimingTags string // filter for balance + BalanceRatingSubject string // filter for balance + BalanceCategory string // filter for balance + BalanceSharedGroup string // filter for balance + MinQueuedItems int // Trigger actions only if this number is hit (stats only) + ActionsId string // Actions which will execute on threshold reached + Weight float64 // weight } diff --git a/utils/apitpdata_test.go b/utils/apitpdata_test.go index 0153df03d..a3a89b9cc 100644 --- a/utils/apitpdata_test.go +++ b/utils/apitpdata_test.go @@ -21,7 +21,6 @@ package utils import ( "reflect" "testing" - "time" ) func TestTPDestinationAsExportSlice(t *testing.T) { @@ -415,7 +414,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) { ThresholdType: "*min_balance", ThresholdValue: 2.0, Recurrent: false, - MinSleep: time.Duration(0), + MinSleep: "0", BalanceId: "b1", BalanceType: "*monetary", BalanceDirection: "*out", @@ -433,7 +432,7 @@ func TestTPActionPlanAsExportSlice(t *testing.T) { ThresholdType: "*max_counter", ThresholdValue: 5.0, Recurrent: false, - MinSleep: time.Duration(0), + MinSleep: "0", BalanceId: "b2", BalanceType: "*monetary", BalanceDirection: "*out",