first draft of stale sessions protection

This commit is contained in:
Radu Ioan Fericean
2015-06-09 14:37:48 +03:00
parent f454707445
commit ab9280dbe5
3 changed files with 85 additions and 58 deletions

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package engine
import (
"errors"
"fmt"
"io/ioutil"
"net/http"
@@ -106,8 +107,15 @@ type CallCostLog struct {
}
// RPC method, used to log callcosts to db
func (self *CdrServer) LogCallCost(ccl *CallCostLog) error {
return self.cdrDb.LogCallCost(ccl.CgrId, ccl.Source, ccl.RunId, ccl.CallCost)
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)
}
// Called by rate/re-rate API

View File

@@ -236,11 +236,12 @@ func (rs *Responder) ProcessCdr(cdr *StoredCdr, reply *string) error {
return nil
}
func (rs *Responder) LogCallCost(ccl *CallCostLog, reply *int) error {
func (rs *Responder) LogCallCost(ccl *CallCostLog, reply *int64) error {
if rs.CdrSrv == nil {
return errors.New("CDR_SERVER_NOT_RUNNING")
}
if err := rs.CdrSrv.LogCallCost(ccl); err != nil {
if duration, err := rs.CdrSrv.LogCallCost(ccl); err != nil {
*reply = int64(duration)
return err
}
*reply = 0
@@ -414,7 +415,7 @@ type Connector interface {
GetDerivedMaxSessionTime(StoredCdr, *float64) error
GetSessionRuns(StoredCdr, *[]*SessionRun) error
ProcessCdr(*StoredCdr, *string) error
LogCallCost(*CallCostLog, *int) error
LogCallCost(*CallCostLog, *int64) error
GetLCR(*CallDescriptor, *LCRCost) error
}
@@ -458,7 +459,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 *int) error {
func (rcc *RPCClientConnector) LogCallCost(ccl *CallCostLog, reply *int64) error {
return rcc.Client.Call("CDRSV1.LogCallCost", ccl, reply)
}