mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Session manager fixups for derived charging
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
#Direction,Tenant,Category,Account,Subject,RunId,ReqTypeField,DirectionField,TenantField,TorField,AccountField,SubjectField,DestinationField,SetupTimeField,AnswerTimeField,UsageField
|
||||
*out,cgrates.org,call,1001,1001,fs_json_run,^rated,*default,*default,*default,1010,1010,*default,*default,*default,*default
|
||||
*out,cgrates.org,call,1001,1001,fs_json_run,^rated,*default,*default,*default,*default,^1002,*default,*default,*default,*default
|
||||
|
||||
|
@@ -109,7 +109,6 @@ func (self *Mediator) rateCDR(storedCdr *utils.StoredCdr) error {
|
||||
}
|
||||
|
||||
func (self *Mediator) RateCdr(storedCdr *utils.StoredCdr) error {
|
||||
engine.Logger.Debug(fmt.Sprintf("Rating CDR: %v", storedCdr))
|
||||
storedCdr.MediationRunId = utils.DEFAULT_RUNID
|
||||
cdrRuns := []*utils.StoredCdr{storedCdr} // Start with initial storCdr, will add here all to be mediated
|
||||
attrsDC := utils.AttrDerivedChargers{Tenant: storedCdr.Tenant, Category: storedCdr.Category, Direction: storedCdr.Direction,
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/fsock"
|
||||
)
|
||||
@@ -202,6 +201,5 @@ func (fsev FSEvent) GetDuration(fieldName string) (dur time.Duration, err error)
|
||||
if strings.HasPrefix(fieldName, utils.STATIC_VALUE_PREFIX) { // Static value
|
||||
durStr = fieldName[len(utils.STATIC_VALUE_PREFIX):]
|
||||
}
|
||||
engine.Logger.Info(fmt.Sprintf("Parsing duration out of string: %s, fieldName: %s, field dur: %s, fsev: %s", durStr, fsev[fieldName], fsev[DURATION], fsev))
|
||||
return utils.ParseDurationWithSecs(durStr)
|
||||
}
|
||||
|
||||
@@ -248,14 +248,18 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
|
||||
return
|
||||
}
|
||||
dcs, _ = dcs.AppendDefaultRun()
|
||||
for idx, dc := range dcs {
|
||||
for _, dc := range dcs {
|
||||
if ev.GetReqType(dc.ReqTypeField) != utils.PREPAID {
|
||||
continue
|
||||
}
|
||||
if len(s.sessionRuns[idx].callCosts) == 0 {
|
||||
sr := s.GetSessionRun(dc.RunId)
|
||||
if sr == nil {
|
||||
continue // Did not save a sessionRun for this dc
|
||||
}
|
||||
if len(sr.callCosts) == 0 {
|
||||
continue // why would we have 0 callcosts
|
||||
}
|
||||
lastCC := s.sessionRuns[idx].callCosts[len(s.sessionRuns[idx].callCosts)-1]
|
||||
lastCC := sr.callCosts[len(sr.callCosts)-1]
|
||||
lastCC.Timespans.Decompress()
|
||||
// put credit back
|
||||
startTime, err := ev.GetAnswerTime(dc.AnswerTimeField)
|
||||
|
||||
@@ -37,6 +37,15 @@ type Session struct {
|
||||
sessionRuns []*SessionRun
|
||||
}
|
||||
|
||||
func (s *Session) GetSessionRun(runid string) *SessionRun {
|
||||
for _, sr := range s.sessionRuns {
|
||||
if sr.runId == runid {
|
||||
return sr
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// One individual run
|
||||
type SessionRun struct {
|
||||
runId string
|
||||
@@ -50,7 +59,6 @@ func NewSession(ev Event, sm SessionManager, dcs utils.DerivedChargers) *Session
|
||||
uuid: ev.GetUUID(),
|
||||
stopDebit: make(chan bool),
|
||||
sessionManager: sm,
|
||||
sessionRuns: make([]*SessionRun, 0),
|
||||
}
|
||||
for _, dc := range dcs {
|
||||
if ev.GetReqType(dc.ReqTypeField) != utils.PREPAID {
|
||||
@@ -99,10 +107,9 @@ func (s *Session) debitLoop(runIdx int) {
|
||||
nextCd.TimeEnd = nextCd.TimeStart.Add(debitPeriod)
|
||||
nextCd.LoopIndex = index
|
||||
nextCd.DurationIndex += debitPeriod // first presumed duration
|
||||
cc := &engine.CallCost{}
|
||||
cc := new(engine.CallCost)
|
||||
if err := s.sessionManager.MaxDebit(&nextCd, cc); err != nil {
|
||||
engine.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err))
|
||||
// disconnect session
|
||||
s.sessionManager.DisconnectSession(s.uuid, SYSTEM_ERROR)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user