mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-13 02:56:24 +05:00
refund everything on duplicate callcost log
This commit is contained in:
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -107,15 +106,8 @@ type CallCostLog struct {
|
||||
}
|
||||
|
||||
// RPC method, used to log callcosts to db
|
||||
func (self *CdrServer) LogCallCost(ccl *CallCostLog) (time.Duration, error) {
|
||||
cc, err := self.cdrDb.GetCallCostLog(ccl.CgrId, ccl.Source, ccl.RunId)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if cc != nil {
|
||||
return cc.GetDuration(), errors.New("duplicate record")
|
||||
}
|
||||
return 0, self.cdrDb.LogCallCost(ccl.CgrId, ccl.Source, ccl.RunId, ccl.CallCost)
|
||||
func (self *CdrServer) LogCallCost(ccl *CallCostLog) error {
|
||||
return self.cdrDb.LogCallCost(ccl.CgrId, ccl.Source, ccl.RunId, ccl.CallCost)
|
||||
}
|
||||
|
||||
// Called by rate/re-rate API
|
||||
|
||||
@@ -236,15 +236,14 @@ func (rs *Responder) ProcessCdr(cdr *StoredCdr, reply *string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *Responder) LogCallCost(ccl *CallCostLog, reply *int64) error {
|
||||
func (rs *Responder) LogCallCost(ccl *CallCostLog, reply *string) error {
|
||||
if rs.CdrSrv == nil {
|
||||
return errors.New("CDR_SERVER_NOT_RUNNING")
|
||||
}
|
||||
if duration, err := rs.CdrSrv.LogCallCost(ccl); err != nil {
|
||||
*reply = int64(duration)
|
||||
if err := rs.CdrSrv.LogCallCost(ccl); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = 0
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -415,7 +414,7 @@ type Connector interface {
|
||||
GetDerivedMaxSessionTime(StoredCdr, *float64) error
|
||||
GetSessionRuns(StoredCdr, *[]*SessionRun) error
|
||||
ProcessCdr(*StoredCdr, *string) error
|
||||
LogCallCost(*CallCostLog, *int64) error
|
||||
LogCallCost(*CallCostLog, *string) error
|
||||
GetLCR(*CallDescriptor, *LCRCost) error
|
||||
}
|
||||
|
||||
@@ -459,7 +458,7 @@ func (rcc *RPCClientConnector) ProcessCdr(cdr *StoredCdr, reply *string) error {
|
||||
return rcc.Client.Call("CDRSV1.ProcessCdr", cdr, reply)
|
||||
}
|
||||
|
||||
func (rcc *RPCClientConnector) LogCallCost(ccl *CallCostLog, reply *int64) error {
|
||||
func (rcc *RPCClientConnector) LogCallCost(ccl *CallCostLog, reply *string) error {
|
||||
return rcc.Client.Call("CDRSV1.LogCallCost", ccl, reply)
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package sessionmanager
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -212,21 +213,19 @@ func (s *Session) SaveOperations() {
|
||||
for _, cc := range sr.CallCosts[1:] {
|
||||
firstCC.Merge(cc)
|
||||
}
|
||||
var savedCallcostDuration int64
|
||||
var reply string
|
||||
err := s.sessionManager.CdrSrv().LogCallCost(&engine.CallCostLog{
|
||||
CgrId: s.eventStart.GetCgrId(),
|
||||
Source: engine.SESSION_MANAGER_SOURCE,
|
||||
RunId: sr.DerivedCharger.RunId,
|
||||
CallCost: firstCC,
|
||||
}, &savedCallcostDuration)
|
||||
// on duplicate error refound extra period compared to existing database callcost
|
||||
}, &reply)
|
||||
// this is a protection against the case when the close event is missed for some reason
|
||||
// when the cdr arrives to cdrserver because our callcost is not there it will be rated
|
||||
// as postpaid. When the close event finally arives we have to refund everything
|
||||
if err != nil {
|
||||
hangupTime := firstCC.Timespans[0].TimeStart.Add(time.Duration(savedCallcostDuration))
|
||||
if savedCallcostDuration > 0 {
|
||||
s.Refund(firstCC, hangupTime)
|
||||
if err == errors.New("unique violation ") { //FIXME: find the right error
|
||||
s.Refund(firstCC, firstCC.Timespans[0].TimeStart)
|
||||
} else {
|
||||
engine.Logger.Err(fmt.Sprintf("failed to log call cost: %v", err))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user