Merge in SMGeneric to store compressed timestamps

This commit is contained in:
DanB
2016-09-16 13:56:44 +02:00
parent b1013e04eb
commit 58086fcf0b
2 changed files with 8 additions and 9 deletions

View File

@@ -132,19 +132,14 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed *time.Duration) (time.
self.callCosts = append(self.callCosts, cc)
self.lastDebit = initialExtraDuration + ccDuration
self.totalUsage += self.lastUsage
//utils.Logger.Debug(fmt.Sprintf("TotalUsage: %f", self.totalUsage.Seconds()))
if ccDuration >= dur { // we got what we asked to be debited
//utils.Logger.Debug(fmt.Sprintf("returning normal: %f", requestedDuration.Seconds()))
return requestedDuration, nil
}
//utils.Logger.Debug(fmt.Sprintf("returning initialExtra: %f + ccDuration: %f", initialExtraDuration.Seconds(), ccDuration.Seconds()))
return initialExtraDuration + ccDuration, nil
}
// Attempts to refund a duration, error on failure
func (self *SMGSession) refund(refundDuration time.Duration) error {
//initialRefundDuration := refundDuration
firstCC := self.callCosts[0] // use merged cc (from close function)
firstCC.Timespans.Decompress()
defer firstCC.Timespans.Compress()
@@ -183,7 +178,6 @@ func (self *SMGSession) refund(refundDuration time.Duration) error {
}
}
// show only what was actualy refunded (stopped in timespan)
// utils.Logger.Info(fmt.Sprintf("Refund duration: %v", initialRefundDuration-refundDuration))
if len(refundIncrements) > 0 {
cd := firstCC.CreateCallDescriptor()
cd.Increments = refundIncrements
@@ -255,6 +249,9 @@ func (self *SMGSession) saveOperations(originID string) error {
return err
}
}
firstCC.Timespans.Decompress()
firstCC.Timespans.Merge() // Here we could wait a while depending on the size of the timespans
firstCC.Timespans.Compress()
smCost := &engine.SMCost{
CGRID: self.eventStart.GetCgrId(self.timezone),
CostSource: utils.SESSION_MANAGER_SOURCE,

View File

@@ -305,9 +305,11 @@ func (self *SMGeneric) sessionEnd(sessionId string, usage time.Duration) error {
if err := s.close(aTime.Add(usage)); err != nil {
utils.Logger.Err(fmt.Sprintf("<SMGeneric> Could not close session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error()))
}
if err := s.saveOperations(sessionId); err != nil {
utils.Logger.Err(fmt.Sprintf("<SMGeneric> Could not save session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error()))
}
go func() { // Call it in goroutine since it could take a while to compress timespans and save them
if err := s.saveOperations(sessionId); err != nil {
utils.Logger.Err(fmt.Sprintf("<SMGeneric> Could not save session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error()))
}
}()
}
return nil, nil
}, time.Duration(2)*time.Second, sessionId)