mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
Updated ProcessEventWithGet for cdrs
This commit is contained in:
committed by
Dan Christian Bogos
parent
8fe9805592
commit
4b1f6ab11a
@@ -185,9 +185,8 @@ func (cdrS *CDRServer) eeSProcessEvent(ctx *context.Context, cgrEv *utils.CGREve
|
||||
|
||||
// processEvent processes a CGREvent based on arguments
|
||||
// in case of partially executed, both error and evs will be returned
|
||||
func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (evs []*utils.EventWithFlags, err error) {
|
||||
func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (evs []*utils.EventsWithOpts, err error) {
|
||||
// making the options
|
||||
|
||||
var attrS bool
|
||||
if attrS, err = GetBoolOpts(ctx, ev.Tenant, ev, cdrS.fltrS, cdrS.cfg.CdrsCfg().Opts.Attributes,
|
||||
config.CDRsAttributesDftOpt, utils.OptsAttributeS); err != nil {
|
||||
@@ -306,6 +305,15 @@ func (cdrS *CDRServer) processEvent(ctx *context.Context, ev *utils.CGREvent) (e
|
||||
}
|
||||
}
|
||||
|
||||
// now that we did all the requested processed events, we have to build our EventsWithOpts
|
||||
evs = make([]*utils.EventsWithOpts, len(cgrEvs))
|
||||
for i, cgrEv := range cgrEvs {
|
||||
evs[i] = &utils.EventsWithOpts{
|
||||
Event: cgrEv.Event,
|
||||
Opts: cgrEv.APIOpts,
|
||||
}
|
||||
}
|
||||
|
||||
if partiallyExecuted {
|
||||
err = utils.ErrPartiallyExecuted
|
||||
}
|
||||
@@ -348,7 +356,7 @@ func (cdrS *CDRServer) V1ProcessEvent(ctx *context.Context, arg *utils.CGREvent,
|
||||
}
|
||||
|
||||
// V1ProcessEventWithGet has the same logic with V1ProcessEvent except it adds the proccessed events to the reply
|
||||
func (cdrS *CDRServer) V1ProcessEventWithGet(ctx *context.Context, arg *utils.CGREvent, evs *[]*utils.EventWithFlags) (err error) {
|
||||
func (cdrS *CDRServer) V1ProcessEventWithGet(ctx *context.Context, arg *utils.CGREvent, evs *[]*utils.EventsWithOpts) (err error) {
|
||||
if arg.ID == utils.EmptyString {
|
||||
arg.ID = utils.GenUUID()
|
||||
}
|
||||
@@ -365,7 +373,7 @@ func (cdrS *CDRServer) V1ProcessEventWithGet(ctx *context.Context, arg *utils.CG
|
||||
if itm, has := Cache.Get(utils.CacheRPCResponses, cacheKey); has {
|
||||
cachedResp := itm.(*utils.CachedRPCResponse)
|
||||
if cachedResp.Error == nil {
|
||||
*evs = *cachedResp.Result.(*[]*utils.EventWithFlags)
|
||||
*evs = *cachedResp.Result.(*[]*utils.EventsWithOpts)
|
||||
}
|
||||
return cachedResp.Error
|
||||
}
|
||||
@@ -375,7 +383,7 @@ func (cdrS *CDRServer) V1ProcessEventWithGet(ctx *context.Context, arg *utils.CG
|
||||
}
|
||||
// end of RPC caching
|
||||
|
||||
var procEvs []*utils.EventWithFlags
|
||||
var procEvs []*utils.EventsWithOpts
|
||||
if procEvs, err = cdrS.processEvent(ctx, arg); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
@@ -2489,11 +2490,12 @@ func TestCDRsV1ProcessEventWithGetMockCache(t *testing.T) {
|
||||
defer func() {
|
||||
config.CgrConfig().CacheCfg().Partitions[utils.CacheRPCResponses] = defaultConf
|
||||
}()
|
||||
var rply []*utils.EventWithFlags
|
||||
var rply []*utils.EventsWithOpts
|
||||
err := newCDRSrv.V1ProcessEventWithGet(context.Background(), cgrEv, &rply)
|
||||
if err != nil {
|
||||
t.Errorf("\nExpected <%+v> \n, received <%+v>", nil, err)
|
||||
}
|
||||
fmt.Println(utils.ToJSON(rply))
|
||||
expected := &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "testID",
|
||||
@@ -2574,7 +2576,7 @@ func TestCDRsV1ProcessEventWithGetMockCacheErr(t *testing.T) {
|
||||
defer func() {
|
||||
config.CgrConfig().CacheCfg().Partitions[utils.CacheRPCResponses] = defaultConf
|
||||
}()
|
||||
var rply []*utils.EventWithFlags
|
||||
var rply []*utils.EventsWithOpts
|
||||
err := newCDRSrv.V1ProcessEventWithGet(context.Background(), cgrEv, &rply)
|
||||
if err == nil || err.Error() != "cannot convert field: 1s to bool" {
|
||||
t.Errorf("\nExpected <%+v> \n, received <%+v>", "cannot convert field: 1s to bool", err)
|
||||
@@ -2712,7 +2714,7 @@ func TestCDRsV1ProcessEventWithGetCacheGet(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
rply := []*utils.EventWithFlags{}
|
||||
rply := []*utils.EventsWithOpts{}
|
||||
Cache.Set(context.Background(), utils.CacheRPCResponses, "CDRsV1.ProcessEvent:testID",
|
||||
&utils.CachedRPCResponse{Result: &rply, Error: nil},
|
||||
nil, true, utils.NonTransactional)
|
||||
|
||||
Reference in New Issue
Block a user