From d99c0c076c84205ad0449f12ae0a3144311353ec Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 13 Dec 2013 12:56:33 +0200 Subject: [PATCH] fixed max debit function --- engine/calldesc.go | 11 +++++------ sessionmanager/fssessionmanager.go | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index 70c69a22a..221ca92c8 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -499,16 +499,15 @@ func (cd *CallDescriptor) Debit() (cc *CallCost, err error) { // Interface method used to add/substract an amount of cents or bonus seconds (as returned by GetCost method) // from user's money balance. -// This methods combines the Debit and GetMaxSessionTime and will debit the max available time as returned +// This methods combines the Debit and GetMaxSessionDuration and will debit the max available time as returned // by the GetMaxSessionTime method. The amount filed has to be filled in call descriptor. func (cd *CallDescriptor) MaxDebit() (cc *CallCost, err error) { - remainingSeconds, err := cd.GetMaxSessionDuration() - // Logger.Debug(fmt.Sprintf("In MaxDebitd remaining seconds: %v", remainingSeconds)) - if err != nil || remainingSeconds == 0 { + remainingDuration, err := cd.GetMaxSessionDuration() + if err != nil || remainingDuration == 0 { return new(CallCost), errors.New("no more credit") } - if remainingSeconds > 0 { // for postpaying client returns -1 - cd.TimeEnd = cd.TimeStart.Add(time.Duration(remainingSeconds) * time.Second) + if remainingDuration > 0 { // for postpaying client returns -1 + cd.TimeEnd = cd.TimeStart.Add(remainingDuration) } return cd.Debit() } diff --git a/sessionmanager/fssessionmanager.go b/sessionmanager/fssessionmanager.go index 0ebdba546..a2019020d 100644 --- a/sessionmanager/fssessionmanager.go +++ b/sessionmanager/fssessionmanager.go @@ -22,14 +22,15 @@ import ( "bufio" "errors" "fmt" - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" - "github.com/cgrates/fsock" "log/syslog" "net" "strings" "time" + + "github.com/cgrates/cgrates/config" + "github.com/cgrates/cgrates/engine" + "github.com/cgrates/cgrates/utils" + "github.com/cgrates/fsock" ) var cfg *config.CGRConfig // Share the configuration with the rest of the package @@ -163,15 +164,16 @@ func (sm *FSSessionManager) OnChannelPark(ev Event) { Destination: ev.GetDestination(), Amount: sm.debitPeriod.Seconds(), TimeStart: startTime} - var remainingSeconds float64 - err = sm.connector.GetMaxSessionTime(cd, &remainingSeconds) + var remainingDurationFloat float64 + err = sm.connector.GetMaxSessionTime(cd, &remainingDurationFloat) if err != nil { engine.Logger.Err(fmt.Sprintf("Could not get max session time for %s: %v", ev.GetUUID(), err)) sm.unparkCall(ev.GetUUID(), ev.GetCallDestNr(), SYSTEM_ERROR) return } - engine.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingSeconds)) - if remainingSeconds == 0 { + remainingDuration := time.Duration(remainingDurationFloat) + engine.Logger.Info(fmt.Sprintf("Remaining seconds: %v", remainingDuration)) + if remainingDuration == 0 { engine.Logger.Info(fmt.Sprintf("Not enough credit for trasferring the call %s for %s.", ev.GetUUID(), cd.GetKey(cd.Subject))) sm.unparkCall(ev.GetUUID(), ev.GetCallDestNr(), INSUFFICIENT_FUNDS) return @@ -294,7 +296,6 @@ func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) { func (sm *FSSessionManager) LoopAction(s *Session, cd *engine.CallDescriptor, index float64) (cc *engine.CallCost) { cc = &engine.CallCost{} cd.LoopIndex = index - cd.Amount = sm.debitPeriod.Seconds() cd.CallDuration += sm.debitPeriod err := sm.connector.MaxDebit(*cd, cc) if err != nil {