Updated sessions structure

This commit is contained in:
Trial97
2021-11-05 12:38:21 +02:00
committed by Dan Christian Bogos
parent 117f6ccb9b
commit 84a63360db
3 changed files with 7 additions and 14 deletions

View File

@@ -237,6 +237,7 @@ func testSeSRplPrepaidActivateSessions(t *testing.T) {
OptsStart: map[string]interface{}{
utils.DebitInterval: "5ms",
},
Chargeable: true,
}, &reply); err != nil {
t.Fatal(err)
} else if reply != utils.OK {

View File

@@ -76,12 +76,12 @@ type Session struct {
ClientConnID string // connection ID towards the client so we can recover from passive
EventStart engine.MapEvent // Event which started the session
DebitInterval time.Duration // execute debits for *prepaid runs
Chargeable bool // used in case of pausing debit
SRuns []*SRun // forked based on ChargerS
OptsStart engine.MapEvent
debitStop chan struct{}
sTerminator *sTerminator // automatic timeout for the session
chargeable bool
}
// Lock exported function from sync.RWMutex

View File

@@ -920,7 +920,7 @@ func (sS *SessionS) newSession(ctx *context.Context, cgrEv *utils.CGREvent, resI
ClientConnID: clntConnID,
DebitInterval: dbtItval,
}
if s.chargeable, err = engine.GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
if s.Chargeable, err = engine.GetBoolOpts(ctx, cgrEv.Tenant, cgrEv, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
config.SessionsChargeableDftOpt, utils.OptsSesChargeable); err != nil {
return
}
@@ -1242,7 +1242,7 @@ func (sS *SessionS) updateSession(ctx *context.Context, s *Session, updtEv, opts
Event: updtEv,
APIOpts: opts,
}
if s.chargeable, err = engine.GetBoolOpts(ctx, event.Tenant, event, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
if s.Chargeable, err = engine.GetBoolOpts(ctx, event.Tenant, event, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
config.SessionsChargeableDftOpt, utils.OptsSesChargeable); err != nil {
return
}
@@ -1314,7 +1314,7 @@ func (sS *SessionS) endSession(ctx *context.Context, s *Session, tUsage, lastUsa
// if sr.EventCost != nil {
// if !isMsg { // in case of one time charge there is no need of corrections
// if notCharged := sUsage - sr.EventCost.GetUsage(); notCharged > 0 { // we did not charge enough, make a manual debit here
// if !s.chargeable {
// if !s.Chargeable {
// sS.pause(sr, notCharged)
// } else {
// if sr.CD.LoopIndex > 0 {
@@ -1498,14 +1498,6 @@ func (sS *SessionS) BiRPCv1SetPassiveSession(ctx *context.Context,
*reply = utils.OK
return
}
if s.chargeable, err = engine.GetBoolOpts(ctx, s.Tenant, &utils.CGREvent{
Tenant: s.Tenant,
Event: s.EventStart,
APIOpts: s.OptsStart,
}, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
config.SessionsChargeableDftOpt, utils.OptsSesChargeable); err != nil {
return
}
if aSs := sS.getSessions(s.CGRID, false); len(aSs) != 0 { // found active session, transit to passive
aSs[0].Lock()
sS.unregisterSession(s.CGRID, false)
@@ -2137,7 +2129,7 @@ func (sS *SessionS) BiRPCv1TerminateSession(ctx *context.Context,
s.UpdateSRuns(ev, sS.cgrCfg.SessionSCfg().AlterableFields)
}
s.Lock()
if s.chargeable, err = engine.GetBoolOpts(ctx, args.Tenant, args, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
if s.Chargeable, err = engine.GetBoolOpts(ctx, args.Tenant, args, sS.filterS, sS.cgrCfg.SessionSCfg().Opts.Chargeable,
config.SessionsChargeableDftOpt, utils.OptsSesChargeable); err != nil {
return
}
@@ -2783,7 +2775,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(ctx *context.Context,
// }
// } else {
// s.Lock()
// s.chargeable = opts.GetBoolOrDefault(utils.OptsChargeable, true)
// s.Chargeable = opts.GetBoolOrDefault(utils.OptsChargeable, true)
// s.Unlock()
// }
// if err = sS.terminateSession(s,