From 3b17eee8e1d24b1f303de892fcaed8a3b258e668 Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 20 Sep 2016 17:35:45 +0200 Subject: [PATCH] SMGeneric saveOperations without goroutines --- engine/callcost.go | 1 + sessionmanager/smg_session.go | 5 ++--- sessionmanager/smgeneric.go | 17 ++++++----------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/engine/callcost.go b/engine/callcost.go index 5e4ee8c75..c04b53ca2 100644 --- a/engine/callcost.go +++ b/engine/callcost.go @@ -29,6 +29,7 @@ type CallCost struct { Direction, Category, Tenant, Subject, Account, Destination, TOR string Cost float64 Timespans TimeSpans + TimespansMerged bool RatedUsage float64 deductConnectFee bool negativeConnectFee bool // the connect fee went negative on default balance diff --git a/sessionmanager/smg_session.go b/sessionmanager/smg_session.go index f2e307127..0eb2665fc 100644 --- a/sessionmanager/smg_session.go +++ b/sessionmanager/smg_session.go @@ -236,11 +236,11 @@ func (self *SMGSession) disconnectSession(reason string) error { // Merge the sum of costs and sends it to CDRS for storage // originID could have been changed from original event, hence passing as argument here // pass cc as the clone of original to avoid concurrency issues -func (self *SMGSession) saveOperations(originID string, cc *engine.CallCost) error { +func (self *SMGSession) saveOperations(originID string) error { if len(self.callCosts) == 0 { return nil // There are no costs to save, ignore the operation } - //firstCC := self.callCosts[0] // was merged in close method + cc := self.callCosts[0] // was merged in close method cc.Round() roundIncrements := cc.GetRoundIncrements() if len(roundIncrements) != 0 { @@ -258,7 +258,6 @@ func (self *SMGSession) saveOperations(originID string, cc *engine.CallCost) err cc.Timespans.Merge() // Here we could wait a while depending on the size of the timespans cc.Timespans.Compress() } - smCost := &engine.SMCost{ CGRID: self.eventStart.GetCgrId(self.timezone), CostSource: utils.SESSION_MANAGER_SOURCE, diff --git a/sessionmanager/smgeneric.go b/sessionmanager/smgeneric.go index 1372cc9dc..76b0fe1ad 100644 --- a/sessionmanager/smgeneric.go +++ b/sessionmanager/smgeneric.go @@ -31,6 +31,10 @@ import ( "github.com/cgrates/rpcclient" ) +const ( + MaxTimespansInCost = 50 +) + var ErrPartiallyExecuted = errors.New("Partially executed") func NewSMGeneric(cgrCfg *config.CGRConfig, rater rpcclient.RpcClientConnection, cdrsrv rpcclient.RpcClientConnection, timezone string, extconns *SMGExternalConnections) *SMGeneric { @@ -305,17 +309,8 @@ func (self *SMGeneric) sessionEnd(sessionId string, usage time.Duration) error { if err := s.close(aTime.Add(usage)); err != nil { utils.Logger.Err(fmt.Sprintf(" Could not close session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error())) } - if len(s.callCosts) != 0 { // Save cost to sm_cost table - var cc engine.CallCost - if err := utils.Clone(*s.callCosts[0], &cc); err != nil { // Avoid concurrency on CC - utils.Logger.Err(fmt.Sprintf(" Could not clone callcost for sessionID: %s, runId: %s, error: %s", sessionId, s.runId, err.Error())) - continue - } - go func(sessionID string, cc *engine.CallCost) { // Call it in goroutine since it could take a while to compress timespans and save them - if err := s.saveOperations(sessionId, cc); err != nil { - utils.Logger.Err(fmt.Sprintf(" Could not save session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error())) - } - }(sessionId, &cc) + if err := s.saveOperations(sessionId); err != nil { + utils.Logger.Err(fmt.Sprintf(" Could not save session: %s, runId: %s, error: %s", sessionId, s.runId, err.Error())) } } return nil, nil