mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 10:36:24 +05:00
SessionS package building
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -139,6 +140,45 @@ func (s *Session) AsActiveSessions(tmz, nodeID string) (aSs []*ActiveSession) {
|
||||
return
|
||||
}
|
||||
|
||||
// TotalUsage returns the first session run total usage
|
||||
func (s *Session) TotalUsage() (tDur time.Duration) {
|
||||
if len(s.SRuns) == 0 {
|
||||
return
|
||||
}
|
||||
s.RLock()
|
||||
for _, sr := range s.SRuns {
|
||||
tDur = sr.TotalUsage
|
||||
break // only first
|
||||
}
|
||||
s.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// AsCGREvents is a thread safe method to return the Session as CGREvents
|
||||
// there will be one CGREvent for each SRun
|
||||
func (s *Session) AsCGREvents(cgrCfg *config.CGRConfig) (cgrEvs []*utils.CGREvent, err error) {
|
||||
if len(s.SRuns) == 0 {
|
||||
return
|
||||
}
|
||||
s.RLock()
|
||||
cgrEvs = make([]*utils.CGREvent, len(s.SRuns)) // so we can gather all cdr info while under lock
|
||||
for i, sr := range s.SRuns {
|
||||
var cdr *engine.CDR
|
||||
if cdr, err = sr.Event.AsCDR(cgrCfg, s.Tenant,
|
||||
cgrCfg.GeneralCfg().DefaultTimezone); err != nil {
|
||||
break // will return with error
|
||||
}
|
||||
cdr.Usage = sr.TotalUsage
|
||||
cgrEvs[i] = &utils.CGREvent{
|
||||
Tenant: s.Tenant,
|
||||
ID: utils.UUIDSha1Prefix(),
|
||||
Event: cdr.AsMapStringIface(),
|
||||
}
|
||||
}
|
||||
s.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
// SRun is one billing run for the Session
|
||||
type SRun struct {
|
||||
Event engine.MapEvent // Event received from ChargerS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -771,7 +771,7 @@ const (
|
||||
SessionSv1GetActiveSessions = "SessionSv1.GetActiveSessions"
|
||||
SessionSv1ForceDisconnect = "SessionSv1.ForceDisconnect"
|
||||
SessionSv1GetPassiveSessions = "SessionSv1.GetPassiveSessions"
|
||||
SessionSv1SetPassiveSessions = "SessionSV1.SetPassiveSessions"
|
||||
SessionSv1SetPassiveSession = "SessionSV1.SetPassiveSession"
|
||||
SMGenericV1InitiateSession = "SMGenericV1.InitiateSession"
|
||||
SMGenericV2InitiateSession = "SMGenericV2.InitiateSession"
|
||||
SMGenericV2UpdateSession = "SMGenericV2.UpdateSession"
|
||||
|
||||
Reference in New Issue
Block a user