This commit is contained in:
DanB
2014-01-12 18:37:40 +01:00
4 changed files with 18 additions and 8 deletions

View File

@@ -368,6 +368,11 @@ func (cd *CallDescriptor) roundTimeSpansToIncrement(timespans TimeSpans) []*Time
return timespans
}
// Returns call descripor's total duration
func (cd *CallDescriptor) GetDuration() time.Duration {
return cd.TimeEnd.Sub(cd.TimeStart)
}
/*
Creates a CallCost structure with the cost information calculated for the received CallDescriptor.
*/

View File

@@ -310,10 +310,8 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
}
func (sm *FSSessionManager) LoopAction(s *Session, cd *engine.CallDescriptor, index float64) (cc *engine.CallCost) {
func (sm *FSSessionManager) LoopAction(s *Session, cd *engine.CallDescriptor) (cc *engine.CallCost) {
cc = &engine.CallCost{}
cd.LoopIndex = index
cd.CallDuration += sm.debitPeriod
err := sm.connector.MaxDebit(*cd, cc)
if err != nil {
engine.Logger.Err(fmt.Sprintf("Could not complete debit opperation: %v", err))

View File

@@ -77,6 +77,7 @@ func NewSession(ev Event, sm SessionManager) (s *Session) {
func (s *Session) startDebitLoop() {
nextCd := *s.callDescriptor
index := 0.0
debitPeriod := s.sessionManager.GetDebitPeriod()
for {
select {
case <-s.stopDebit:
@@ -86,9 +87,14 @@ func (s *Session) startDebitLoop() {
if index > 0 { // first time use the session start time
nextCd.TimeStart = nextCd.TimeEnd
}
nextCd.TimeEnd = nextCd.TimeStart.Add(s.sessionManager.GetDebitPeriod())
cc := s.sessionManager.LoopAction(s, &nextCd, index)
nextCd.TimeEnd = cc.GetEndTime()
nextCd.TimeEnd = nextCd.TimeStart.Add(debitPeriod)
nextCd.LoopIndex = index
nextCd.CallDuration += debitPeriod // first presumed duration
cc := s.sessionManager.LoopAction(s, &nextCd)
nextCd.TimeEnd = cc.GetEndTime() // set debited timeEnd
// update call duration with real debited duration
nextCd.CallDuration -= debitPeriod
nextCd.CallDuration += nextCd.GetDuration()
time.Sleep(cc.GetDuration())
index++
}

View File

@@ -19,16 +19,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package sessionmanager
import (
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"time"
)
type SessionManager interface {
Connect(*config.CGRConfig) error
DisconnectSession(*Session, string)
RemoveSession(*Session)
LoopAction(*Session, *engine.CallDescriptor, float64) *engine.CallCost
LoopAction(*Session, *engine.CallDescriptor) *engine.CallCost
GetDebitPeriod() time.Duration
GetDbLogger() engine.LogStorage
Shutdown() error