mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
more fixes for action trigger db load
This commit is contained in:
@@ -184,7 +184,13 @@ CREATE TABLE `tp_action_triggers` (
|
||||
`threshold_type` char(12) NOT NULL,
|
||||
`threshold_value` double(20,4) NOT NULL,
|
||||
`recurrent` bool NOT NULL,
|
||||
`min_sleep` int(11) NOT NULL,
|
||||
`destination_id` varchar(64) NOT NULL,
|
||||
`balance_weight` double(8,2) NOT NULL,
|
||||
`balance_expiry_time` varchar(24) NOT NULL,
|
||||
`balance_rating_subject` varchar(64) NOT NULL,
|
||||
`balance_shared_group` varchar(64) NOT NULL,
|
||||
`min_queued_items` int(11) NOT NULL,
|
||||
`actions_id` varchar(64) NOT NULL,
|
||||
`weight` double(8,2) NOT NULL,
|
||||
PRIMARY KEY (`tbid`),
|
||||
|
||||
@@ -579,15 +579,23 @@ func (dbr *DbReader) LoadActionTriggers() (err error) {
|
||||
for key, atrsLst := range atrsMap {
|
||||
atrs := make([]*ActionTrigger, len(atrsLst))
|
||||
for idx, apiAtr := range atrsLst {
|
||||
atrs[idx] = &ActionTrigger{Id: utils.GenUUID(),
|
||||
BalanceType: apiAtr.BalanceType,
|
||||
Direction: apiAtr.Direction,
|
||||
ThresholdType: apiAtr.ThresholdType,
|
||||
ThresholdValue: apiAtr.ThresholdValue,
|
||||
Recurrent: apiAtr.Recurrent,
|
||||
DestinationId: apiAtr.DestinationId,
|
||||
Weight: apiAtr.Weight,
|
||||
ActionsId: apiAtr.ActionsId,
|
||||
balance_expiration_date, _ := utils.ParseTimeDetectLayout(apiAtr.BalanceExpirationDate)
|
||||
atrs[idx] = &ActionTrigger{
|
||||
Id: utils.GenUUID(),
|
||||
BalanceType: apiAtr.BalanceType,
|
||||
Direction: apiAtr.Direction,
|
||||
ThresholdType: apiAtr.ThresholdType,
|
||||
ThresholdValue: apiAtr.ThresholdValue,
|
||||
Recurrent: apiAtr.Recurrent,
|
||||
MinSleep: apiAtr.MinSleep,
|
||||
DestinationId: apiAtr.DestinationId,
|
||||
BalanceWeight: apiAtr.BalanceWeight,
|
||||
BalanceExpirationDate: balance_expiration_date,
|
||||
BalanceRatingSubject: apiAtr.BalanceRatingSubject,
|
||||
BalanceSharedGroup: apiAtr.BalanceSharedGroup,
|
||||
Weight: apiAtr.Weight,
|
||||
ActionsId: apiAtr.ActionsId,
|
||||
MinQueuedItems: apiAtr.MinQueuedItems,
|
||||
}
|
||||
}
|
||||
dbr.actionsTriggers[key] = atrs
|
||||
@@ -799,6 +807,10 @@ func (dbr *DbReader) LoadDerivedChargers() (err error) {
|
||||
return nil // Placeholder for now
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadCdrStats() (err error) {
|
||||
return nil // Placeholder for now
|
||||
}
|
||||
|
||||
// Automated loading
|
||||
func (dbr *DbReader) LoadAll() error {
|
||||
var err error
|
||||
|
||||
@@ -1332,7 +1332,7 @@ func (self *SQLStorage) GetTpActions(tpid, tag string) (map[string][]*utils.TPAc
|
||||
|
||||
func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*utils.TPActionTrigger, error) {
|
||||
ats := make(map[string][]*utils.TPActionTrigger)
|
||||
q := fmt.Sprintf("SELECT tpid,id,balance_type,direction,threshold_type,threshold_value,recurrent,destination_id,actions_id,weight FROM %s WHERE tpid='%s'",
|
||||
q := fmt.Sprintf("SELECT tpid,id,balance_type,direction,threshold_type,threshold_value,recurrent,min_sleep, ,destination_id, balance_weight, balance_expiration_time, balance_rating_subject, balance_expiration_time, balance_shared_group, min_queued_items, actions_id, weight FROM %s WHERE tpid='%s'",
|
||||
utils.TBL_TP_ACTION_TRIGGERS, tpid)
|
||||
if tag != "" {
|
||||
q += fmt.Sprintf(" AND id='%s'", tag)
|
||||
@@ -1343,22 +1343,30 @@ func (self *SQLStorage) GetTpActionTriggers(tpid, tag string) (map[string][]*uti
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var threshold, weight float64
|
||||
var tpid, tag, balances_type, direction, destinations_tag, actions_tag, thresholdType string
|
||||
var threshold, balance_weight, weight float64
|
||||
var tpid, tag, balances_type, direction, destinations_tag, balance_expiration_time, balance_rating_subject, balance_shared_group, actions_tag, threshold_type string
|
||||
var recurrent bool
|
||||
if err := rows.Scan(&tpid, &tag, &balances_type, &direction, &thresholdType, &threshold, &recurrent, &destinations_tag, &actions_tag, &weight); err != nil {
|
||||
var min_sleep time.Duration
|
||||
var min_queued_items int
|
||||
if err := rows.Scan(&tpid, &tag, &balances_type, &direction, &threshold_type, &threshold, &recurrent, &min_sleep, &destinations_tag, &actions_tag, &weight); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
at := &utils.TPActionTrigger{
|
||||
BalanceType: balances_type,
|
||||
Direction: direction,
|
||||
ThresholdType: thresholdType,
|
||||
ThresholdValue: threshold,
|
||||
Recurrent: recurrent,
|
||||
DestinationId: destinations_tag,
|
||||
ActionsId: actions_tag,
|
||||
Weight: weight,
|
||||
BalanceType: balances_type,
|
||||
Direction: direction,
|
||||
ThresholdType: threshold_type,
|
||||
ThresholdValue: threshold,
|
||||
Recurrent: recurrent,
|
||||
MinSleep: min_sleep,
|
||||
DestinationId: destinations_tag,
|
||||
BalanceWeight: balance_weight,
|
||||
BalanceExpirationDate: balance_expiration_time,
|
||||
BalanceRatingSubject: balance_rating_subject,
|
||||
BalanceSharedGroup: balance_shared_group,
|
||||
Weight: weight,
|
||||
ActionsId: actions_tag,
|
||||
MinQueuedItems: min_queued_items,
|
||||
}
|
||||
ats[tag] = append(ats[tag], at)
|
||||
}
|
||||
|
||||
@@ -241,14 +241,21 @@ type TPActionTriggers struct {
|
||||
}
|
||||
|
||||
type TPActionTrigger struct {
|
||||
BalanceType string // Type of balance this trigger monitors
|
||||
Direction string // Traffic direction
|
||||
ThresholdType string // This threshold type
|
||||
ThresholdValue float64 // Threshold
|
||||
Recurrent bool // reset executed flag each run
|
||||
DestinationId string // Id of the destination profile
|
||||
ActionsId string // Actions which will execute on threshold reached
|
||||
Weight float64 // weight
|
||||
BalanceType string // Type of balance this trigger monitors
|
||||
Direction string // Traffic direction
|
||||
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
|
||||
DestinationId string // filter for balance
|
||||
BalanceWeight float64 // filter for balance
|
||||
BalanceExpirationDate string // filter for balance
|
||||
BalanceRatingSubject 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
|
||||
|
||||
}
|
||||
|
||||
// Used to rebuild a TPAccountActions (empty ActionTimingsId and ActionTriggersId) out of it's key in nosqldb
|
||||
|
||||
Reference in New Issue
Block a user