IsActiveAtTime use CGREvent.Time

This commit is contained in:
TeoV
2018-01-31 13:57:42 +02:00
committed by Dan Christian Bogos
parent 8d1e7b327c
commit 41f08bad63
5 changed files with 19 additions and 32 deletions

View File

@@ -20,7 +20,6 @@ package engine
import (
"fmt"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/guardian"
@@ -81,12 +80,8 @@ func (alS *AttributeService) matchingAttributeProfilesForEvent(ev *utils.CGREven
}
return nil, err
}
evTime := time.Now()
if ev.Time != nil {
evTime = *ev.Time
}
if aPrfl.ActivationInterval != nil &&
!aPrfl.ActivationInterval.IsActiveAtTime(evTime) { // not active
if aPrfl.ActivationInterval != nil && ev.Time != nil &&
!aPrfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
continue
}
if pass, err := alS.filterS.PassFiltersForEvent(ev.Tenant,

View File

@@ -436,10 +436,10 @@ func (rS *ResourceService) cachedResourcesForEvent(evUUID string) (rs Resources)
}
// matchingResourcesForEvent returns ordered list of matching resources which are active by the time of the call
func (rS *ResourceService) matchingResourcesForEvent(tenant string, ev map[string]interface{}) (rs Resources, err error) {
func (rS *ResourceService) matchingResourcesForEvent(ev *utils.CGREvent) (rs Resources, err error) {
matchingResources := make(map[string]*Resource)
rIDs, err := matchingItemIDsForEvent(ev, rS.stringIndexedFields, rS.prefixIndexedFields,
rS.dm, utils.ResourceFilterIndexes+tenant)
rIDs, err := matchingItemIDsForEvent(ev.Event, rS.stringIndexedFields, rS.prefixIndexedFields,
rS.dm, utils.ResourceFilterIndexes+ev.Tenant)
if err != nil {
return nil, err
}
@@ -447,18 +447,18 @@ func (rS *ResourceService) matchingResourcesForEvent(tenant string, ev map[strin
guardian.Guardian.GuardIDs(config.CgrConfig().LockingTimeout, lockIDs...)
defer guardian.Guardian.UnguardIDs(lockIDs...)
for resName := range rIDs {
rPrf, err := rS.dm.GetResourceProfile(tenant, resName, false, utils.NonTransactional)
rPrf, err := rS.dm.GetResourceProfile(ev.Tenant, resName, false, utils.NonTransactional)
if err != nil {
if err == utils.ErrNotFound {
continue
}
return nil, err
}
if rPrf.ActivationInterval != nil &&
!rPrf.ActivationInterval.IsActiveAtTime(time.Now()) { // not active
if rPrf.ActivationInterval != nil && ev.Time != nil &&
!rPrf.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
continue
}
if pass, err := rS.filterS.PassFiltersForEvent(tenant, ev, rPrf.FilterIDs); err != nil {
if pass, err := rS.filterS.PassFiltersForEvent(ev.Tenant, ev.Event, rPrf.FilterIDs); err != nil {
return nil, err
} else if !pass {
continue
@@ -529,7 +529,7 @@ func (rS *ResourceService) V1ResourcesForEvent(args utils.ArgRSv1ResourceUsage,
mtcRLs = rS.cachedResourcesForEvent(args.TenantID())
}
if mtcRLs == nil {
if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil {
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent); err != nil {
return err
}
cache.Set(utils.EventResourcesPrefix+args.TenantID(), mtcRLs.tenantIDs(), true, "")
@@ -552,7 +552,7 @@ func (rS *ResourceService) V1AuthorizeResources(args utils.ArgRSv1ResourceUsage,
}
mtcRLs := rS.cachedResourcesForEvent(args.TenantID())
if mtcRLs == nil {
if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil {
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent); err != nil {
return err
}
cache.Set(utils.EventResourcesPrefix+args.TenantID(), mtcRLs.tenantIDs(), true, "")
@@ -583,7 +583,7 @@ func (rS *ResourceService) V1AllocateResource(args utils.ArgRSv1ResourceUsage, r
var wasCached bool
mtcRLs := rS.cachedResourcesForEvent(args.UsageID)
if mtcRLs == nil {
if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil {
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent); err != nil {
return
}
} else {
@@ -638,7 +638,7 @@ func (rS *ResourceService) V1ReleaseResource(args utils.ArgRSv1ResourceUsage, re
}
mtcRLs := rS.cachedResourcesForEvent(args.UsageID)
if mtcRLs == nil {
if mtcRLs, err = rS.matchingResourcesForEvent(args.CGREvent.Tenant, args.CGREvent.Event); err != nil {
if mtcRLs, err = rS.matchingResourcesForEvent(&args.CGREvent); err != nil {
return
}
}

View File

@@ -159,8 +159,8 @@ func (sS *StatService) matchingStatQueuesForEvent(ev *utils.CGREvent) (sqs StatQ
}
return nil, err
}
if sqPrfl.ActivationInterval != nil &&
!sqPrfl.ActivationInterval.IsActiveAtTime(time.Now()) { // not active
if sqPrfl.ActivationInterval != nil && ev.Time != nil &&
!sqPrfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
continue
}
if pass, err := sS.filterS.PassFiltersForEvent(ev.Tenant, ev.Event, sqPrfl.FilterIDs); err != nil {

View File

@@ -132,16 +132,8 @@ func (spS *SupplierService) matchingSupplierProfilesForEvent(ev *utils.CGREvent)
}
return nil, err
}
aTime, err := ev.FieldAsTime(utils.AnswerTime, spS.timezone)
if err != nil {
if err == utils.ErrNotFound {
aTime = time.Now()
} else {
return nil, err
}
}
if splPrfl.ActivationInterval != nil &&
!splPrfl.ActivationInterval.IsActiveAtTime(aTime) { // not active
if splPrfl.ActivationInterval != nil && ev.Time != nil &&
!splPrfl.ActivationInterval.IsActiveAtTime(*ev.Time) { // not active
continue
}
if pass, err := spS.filterS.PassFiltersForEvent(ev.Tenant,

View File

@@ -239,8 +239,8 @@ func (tS *ThresholdService) matchingThresholdsForEvent(args *ArgsProcessEvent) (
}
return nil, err
}
if tPrfl.ActivationInterval != nil &&
!tPrfl.ActivationInterval.IsActiveAtTime(time.Now()) { // not active
if tPrfl.ActivationInterval != nil && args.Time != nil &&
!tPrfl.ActivationInterval.IsActiveAtTime(*args.Time) { // not active
continue
}
if pass, err := tS.filterS.PassFiltersForEvent(args.Tenant, args.Event, tPrfl.FilterIDs); err != nil {