mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
started rating unit implementation
This commit is contained in:
@@ -66,3 +66,10 @@ func (cc *CallCost) GetStartTime() time.Time {
|
||||
}
|
||||
return cc.Timespans[0].TimeStart
|
||||
}
|
||||
|
||||
func (cc *CallCost) GetTotalDuration() (td time.Duration) {
|
||||
for _, ts := range cc.Timespans {
|
||||
td += ts.GetDuration()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -315,8 +315,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, index float64) (cc *engine.CallCost) {
|
||||
cc = &engine.CallCost{}
|
||||
cd.LoopIndex = index
|
||||
cd.Amount = sm.debitPeriod.Seconds()
|
||||
cd.CallDuration += time.Duration(cd.Amount) * time.Second
|
||||
@@ -326,18 +326,14 @@ func (sm *FSSessionManager) LoopAction(s *Session, cd *engine.CallDescriptor, in
|
||||
// disconnect session
|
||||
s.sessionManager.DisconnectSession(s, SYSTEM_ERROR)
|
||||
}
|
||||
nbts := len(cc.Timespans)
|
||||
remainingSeconds := 0.0
|
||||
engine.Logger.Debug(fmt.Sprintf("Result of MaxDebit call: %v", cc))
|
||||
if nbts > 0 {
|
||||
remainingSeconds = cc.Timespans[nbts-1].TimeEnd.Sub(cc.Timespans[0].TimeStart).Seconds()
|
||||
}
|
||||
if remainingSeconds == 0 || err != nil {
|
||||
if cc.GetTotalDuration() == 0 || err != nil {
|
||||
engine.Logger.Info(fmt.Sprintf("No credit left: Disconnect %v", s))
|
||||
sm.DisconnectSession(s, INSUFFICIENT_FUNDS)
|
||||
return
|
||||
}
|
||||
s.CallCosts = append(s.CallCosts, cc)
|
||||
return
|
||||
}
|
||||
|
||||
func (sm *FSSessionManager) GetDebitPeriod() time.Duration {
|
||||
|
||||
@@ -86,8 +86,8 @@ func (s *Session) startDebitLoop() {
|
||||
nextCd.TimeStart = nextCd.TimeEnd
|
||||
}
|
||||
nextCd.TimeEnd = nextCd.TimeStart.Add(s.sessionManager.GetDebitPeriod())
|
||||
s.sessionManager.LoopAction(s, &nextCd, index)
|
||||
time.Sleep(s.sessionManager.GetDebitPeriod())
|
||||
cc := s.sessionManager.LoopAction(s, &nextCd, index)
|
||||
time.Sleep(cc.GetTotalDuration())
|
||||
index++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ type SessionManager interface {
|
||||
Connect(*config.CGRConfig) error
|
||||
DisconnectSession(*Session, string)
|
||||
RemoveSession(*Session)
|
||||
LoopAction(*Session, *engine.CallDescriptor, float64)
|
||||
LoopAction(*Session, *engine.CallDescriptor, float64) *engine.CallCost
|
||||
GetDebitPeriod() time.Duration
|
||||
GetDbLogger() engine.LogStorage
|
||||
Shutdown() error
|
||||
|
||||
Reference in New Issue
Block a user