TPActionTriggers-MinSleep from int to string

This commit is contained in:
DanB
2015-02-24 09:50:14 +01:00
parent 9bbc672ba1
commit a4bbad4001
8 changed files with 31 additions and 34 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -163,7 +163,7 @@ type TpActionTrigger struct {
ThresholdType string
ThresholdValue float64
Recurrent bool
MinSleep int64
MinSleep string
BalanceTag string
BalanceType string
BalanceDirection string

View File

@@ -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,

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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",