mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
@@ -112,6 +112,7 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cdrsIndexes
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
ms.cnter = utils.NewCounterGen(1000)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -123,6 +124,7 @@ type MongoStorage struct {
|
||||
cacheCfg *config.CacheConfig
|
||||
loadHistorySize int
|
||||
cdrsIndexes []string
|
||||
cnter *utils.CounterGen
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) conn(col string) (*mgo.Session, *mgo.Collection) {
|
||||
|
||||
@@ -883,7 +883,7 @@ func (ms *MongoStorage) GetSMCosts(cgrid, runid, originHost, originIDPrefix stri
|
||||
|
||||
func (ms *MongoStorage) SetCDR(cdr *CDR, allowUpdate bool) (err error) {
|
||||
if cdr.OrderID == 0 {
|
||||
cdr.OrderID = time.Now().UnixNano()
|
||||
cdr.OrderID = time.Now().UnixNano() + ms.cnter.Gen()
|
||||
}
|
||||
session, col := ms.conn(utils.TBL_CDRS)
|
||||
defer session.Close()
|
||||
|
||||
@@ -1519,7 +1519,7 @@ func testStorDBitCRUDCDRs(t *testing.T) {
|
||||
&CDR{
|
||||
CGRID: "88ed9c38005f07576a1e1af293063833b60edcc6",
|
||||
RunID: "1",
|
||||
OrderID: 1,
|
||||
OrderID: 0,
|
||||
OriginHost: "host1",
|
||||
OriginID: "1",
|
||||
CostDetails: &CallCost{Timespans: TimeSpans{}},
|
||||
@@ -1528,7 +1528,7 @@ func testStorDBitCRUDCDRs(t *testing.T) {
|
||||
&CDR{
|
||||
CGRID: "88ed9c38005f07576a1e1af293063833b60edcc2",
|
||||
RunID: "2",
|
||||
OrderID: 2,
|
||||
OrderID: 0,
|
||||
OriginHost: "host2",
|
||||
OriginID: "2",
|
||||
CostDetails: &CallCost{Timespans: TimeSpans{}},
|
||||
|
||||
@@ -36,9 +36,29 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewCounterGen(limit int64) *CounterGen {
|
||||
return &CounterGen{limit: limit}
|
||||
}
|
||||
|
||||
type CounterGen struct {
|
||||
cnt, limit int64
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func (cg *CounterGen) Gen() int64 {
|
||||
cg.Lock()
|
||||
defer cg.Unlock()
|
||||
cg.cnt += 1
|
||||
if cg.cnt > cg.limit {
|
||||
cg.cnt = 0
|
||||
}
|
||||
return cg.cnt
|
||||
}
|
||||
|
||||
// Returns first non empty string out of vals. Useful to extract defaults
|
||||
func FirstNonEmpty(vals ...string) string {
|
||||
for _, val := range vals {
|
||||
|
||||
Reference in New Issue
Block a user