diff --git a/engine/callcost.go b/engine/callcost.go index cbce826ad..da48636eb 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -67,6 +67,13 @@ func (cc *CallCost) GetStartTime() time.Time { return cc.Timespans[0].TimeStart } +func (cc *CallCost) GetEndTime() time.Time { + if len(cc.Timespans) == 0 { + return time.Now() + } + return cc.Timespans[len(cc.Timespans)-1].TimeEnd +} + func (cc *CallCost) GetDuration() (td time.Duration) { for _, ts := range cc.Timespans { td += ts.GetDuration() diff --git a/sessionmanager/session.go b/sessionmanager/session.go index b0d970f59..2af31f6f8 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -20,9 +20,10 @@ package sessionmanager import ( "fmt" + "time" + "github.com/cgrates/cgrates/engine" "github.com/cgrates/cgrates/utils" - "time" ) // Session type holding the call information fields, a session delegate for specific @@ -87,6 +88,7 @@ func (s *Session) startDebitLoop() { } nextCd.TimeEnd = nextCd.TimeStart.Add(s.sessionManager.GetDebitPeriod()) cc := s.sessionManager.LoopAction(s, &nextCd, index) + nextCd.TimeEnd = cc.GetEndTime() time.Sleep(cc.GetDuration()) index++ }