New config option - attributes.process_runs

This commit is contained in:
DanB
2018-07-19 18:21:26 +02:00
parent 6e3acfb000
commit ec06fe613c
9 changed files with 22 additions and 4 deletions

View File

@@ -582,7 +582,9 @@ func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnec
<-cacheS.GetPrecacheChannel(utils.CacheAttributeProfiles)
aS, err := engine.NewAttributeService(dm, filterS,
cfg.AttributeSCfg().StringIndexedFields, cfg.AttributeSCfg().PrefixIndexedFields)
cfg.AttributeSCfg().StringIndexedFields,
cfg.AttributeSCfg().PrefixIndexedFields,
cfg.AttributeSCfg().ProcessRuns)
if err != nil {
utils.Logger.Crit(
fmt.Sprintf("<%s> Could not init, error: %s",

View File

@@ -23,6 +23,7 @@ type AttributeSCfg struct {
Enabled bool
StringIndexedFields *[]string
PrefixIndexedFields *[]string
ProcessRuns int
}
func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error) {
@@ -46,5 +47,8 @@ func (alS *AttributeSCfg) loadFromJsonCfg(jsnCfg *AttributeSJsonCfg) (err error)
}
alS.PrefixIndexedFields = &pif
}
if jsnCfg.Process_runs != nil {
alS.ProcessRuns = *jsnCfg.Process_runs
}
return
}

View File

@@ -658,6 +658,11 @@ func (self *CGRConfig) checkConfigSanity() error {
}
}
}
if self.attributeSCfg != nil && self.attributeSCfg.Enabled {
if self.attributeSCfg.ProcessRuns < 1 {
return fmt.Errorf("<%s> process_runs needs to be bigger than 0", utils.AttributeS)
}
}
if self.chargerSCfg != nil && self.chargerSCfg.Enabled {
for _, connCfg := range self.chargerSCfg.AttributeSConns {
if connCfg.Address == utils.MetaInternal &&

View File

@@ -430,6 +430,7 @@ const CGRATES_CFG_JSON = `
"enabled": false, // starts attribute service: <true|false>.
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
"prefix_indexed_fields": [], // query indexes based on these fields for faster processing
"process_runs": 1, // number of run loops when processing event
},

View File

@@ -705,6 +705,7 @@ func TestDfAttributeServJsonCfg(t *testing.T) {
Enabled: utils.BoolPointer(false),
String_indexed_fields: nil,
Prefix_indexed_fields: &[]string{},
Process_runs: utils.IntPointer(1),
}
if cfg, err := dfCgrJsonCfg.AttributeServJsonCfg(); err != nil {
t.Error(err)

View File

@@ -805,6 +805,7 @@ func TestCgrCfgJSONDefaultSAttributeSCfg(t *testing.T) {
Enabled: false,
StringIndexedFields: nil,
PrefixIndexedFields: &[]string{},
ProcessRuns: 1,
}
if !reflect.DeepEqual(eAliasSCfg, cgrCfg.attributeSCfg) {
t.Errorf("received: %+v, expecting: %+v", eAliasSCfg, cgrCfg.attributeSCfg)

View File

@@ -427,6 +427,7 @@ type AttributeSJsonCfg struct {
Enabled *bool
String_indexed_fields *[]string
Prefix_indexed_fields *[]string
Process_runs *int
}
// ChargerSJsonCfg service config section

View File

@@ -25,10 +25,12 @@ import (
)
func NewAttributeService(dm *DataManager, filterS *FilterS,
stringIndexedFields, prefixIndexedFields *[]string) (*AttributeService, error) {
stringIndexedFields, prefixIndexedFields *[]string,
processRuns int) (*AttributeService, error) {
return &AttributeService{dm: dm, filterS: filterS,
stringIndexedFields: stringIndexedFields,
prefixIndexedFields: prefixIndexedFields}, nil
prefixIndexedFields: prefixIndexedFields,
processRuns: processRuns}, nil
}
type AttributeService struct {
@@ -36,6 +38,7 @@ type AttributeService struct {
filterS *FilterS
stringIndexedFields *[]string
prefixIndexedFields *[]string
processRuns int
}
// ListenAndServe will initialize the service

View File

@@ -182,7 +182,7 @@ func TestAttributePopulateAttrService(t *testing.T) {
if err != nil {
t.Errorf("Error: %+v", err)
}
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil)
attrService, err = NewAttributeService(dmAtr, &FilterS{dm: dmAtr, cfg: defaultCfg}, nil, nil, 1)
if err != nil {
t.Errorf("Error: %+v", err)
}