mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-23 08:08:45 +05:00
Added profile_runs in attributes
This commit is contained in:
committed by
Dan Christian Bogos
parent
7993a409a5
commit
d3f58e311d
@@ -56,7 +56,7 @@ func (alS *AttributeService) Shutdown() {
|
||||
|
||||
// attributeProfileForEvent returns the matching attribute
|
||||
func (alS *AttributeService) attributeProfileForEvent(ctx *context.Context, tnt string, attrsIDs []string,
|
||||
evNm utils.MapStorage, lastID string) (matchAttrPrfl *AttributeProfile, err error) {
|
||||
evNm utils.MapStorage, lastID string, processedPrfNo map[string]int, profileRuns int) (matchAttrPrfl *AttributeProfile, err error) {
|
||||
var attrIDs []string
|
||||
if len(attrsIDs) != 0 {
|
||||
attrIDs = attrsIDs
|
||||
@@ -82,7 +82,8 @@ func (alS *AttributeService) attributeProfileForEvent(ctx *context.Context, tnt
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
(evNm[utils.MetaVars].(utils.MapStorage))[utils.MetaAttrPrfTenantID] = aPrfl.TenantIDInline()
|
||||
tntID := aPrfl.TenantIDInline()
|
||||
(evNm[utils.MetaVars].(utils.MapStorage))[utils.MetaAttrPrfTenantID] = tntID
|
||||
if pass, err := alS.filterS.Pass(ctx, tnt, aPrfl.FilterIDs,
|
||||
evNm); err != nil {
|
||||
return nil, err
|
||||
@@ -90,7 +91,8 @@ func (alS *AttributeService) attributeProfileForEvent(ctx *context.Context, tnt
|
||||
continue
|
||||
}
|
||||
if (matchAttrPrfl == nil || matchAttrPrfl.Weight < aPrfl.Weight) &&
|
||||
aPrfl.TenantIDInline() != lastID {
|
||||
tntID != lastID &&
|
||||
(profileRuns <= 0 || processedPrfNo[tntID] < profileRuns) {
|
||||
matchAttrPrfl = aPrfl
|
||||
}
|
||||
}
|
||||
@@ -163,10 +165,10 @@ func (attr *AttrArgsProcessEvent) Clone() *AttrArgsProcessEvent {
|
||||
}
|
||||
|
||||
// processEvent will match event with attribute profile and do the necessary replacements
|
||||
func (alS *AttributeService) processEvent(ctx *context.Context, tnt string, args *AttrArgsProcessEvent, evNm utils.MapStorage, dynDP utils.DataProvider, lastID string) (
|
||||
rply *AttrSProcessEventReply, err error) {
|
||||
func (alS *AttributeService) processEvent(ctx *context.Context, tnt string, args *AttrArgsProcessEvent, evNm utils.MapStorage, dynDP utils.DataProvider,
|
||||
lastID string, processedPrfNo map[string]int, profileRuns int) (rply *AttrSProcessEventReply, err error) {
|
||||
var attrPrf *AttributeProfile
|
||||
if attrPrf, err = alS.attributeProfileForEvent(ctx, tnt, args.AttributeIDs, evNm, lastID); err != nil {
|
||||
if attrPrf, err = alS.attributeProfileForEvent(ctx, tnt, args.AttributeIDs, evNm, lastID, processedPrfNo, profileRuns); err != nil {
|
||||
return
|
||||
}
|
||||
rply = &AttrSProcessEventReply{
|
||||
@@ -241,7 +243,7 @@ func (alS *AttributeService) V1GetAttributeForEvent(ctx *context.Context, args *
|
||||
utils.MetaVars: utils.MapStorage{
|
||||
utils.OptsAttributesProcessRuns: 0,
|
||||
},
|
||||
}, utils.EmptyString)
|
||||
}, utils.EmptyString, make(map[string]int), 0)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -272,8 +274,17 @@ func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *AttrArgs
|
||||
return
|
||||
}
|
||||
|
||||
profileRuns := alS.cgrcfg.AttributeSCfg().ProfileRuns
|
||||
if opt, has := args.APIOpts[utils.OptsAttributesProfileRuns]; has {
|
||||
var val int64
|
||||
if val, err = utils.IfaceAsTInt64(opt); err != nil {
|
||||
return
|
||||
}
|
||||
profileRuns = int(val)
|
||||
}
|
||||
args.CGREvent = args.CGREvent.Clone()
|
||||
processedPrf := make(utils.StringSet)
|
||||
processedPrfNo := make(map[string]int)
|
||||
eNV := utils.MapStorage{
|
||||
utils.MetaVars: utils.MapStorage{
|
||||
utils.OptsAttributesProcessRuns: 0,
|
||||
@@ -296,7 +307,7 @@ func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *AttrArgs
|
||||
for i := int64(0); i < processRuns; i++ {
|
||||
(eNV[utils.MetaVars].(utils.MapStorage))[utils.OptsAttributesProcessRuns] = i + 1
|
||||
var evRply *AttrSProcessEventReply
|
||||
evRply, err = alS.processEvent(ctx, tnt, args, eNV, dynDP, lastID)
|
||||
evRply, err = alS.processEvent(ctx, tnt, args, eNV, dynDP, lastID, processedPrfNo, profileRuns)
|
||||
if err != nil {
|
||||
if err != utils.ErrNotFound {
|
||||
err = utils.NewErrServerError(err)
|
||||
@@ -310,6 +321,7 @@ func (alS *AttributeService) V1ProcessEvent(ctx *context.Context, args *AttrArgs
|
||||
lastID = evRply.MatchedProfiles[0]
|
||||
matchedIDs = append(matchedIDs, lastID)
|
||||
processedPrf.Add(lastID)
|
||||
processedPrfNo[lastID] = processedPrfNo[lastID] + 1
|
||||
for _, fldName := range evRply.AlteredFields {
|
||||
alteredFields.Add(fldName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user