mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 13:19:53 +05:00
Mongo counter fix
This commit is contained in:
@@ -112,7 +112,7 @@ func NewMongoStorage(host, port, db, user, pass, storageType string, cdrsIndexes
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
ms.cnter = utils.NewCounterGen(1000)
|
||||
ms.cnter = utils.NewCounterGen(0)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -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() + ms.cnter.Gen()
|
||||
cdr.OrderID = ms.cnter.Gen()
|
||||
}
|
||||
session, col := ms.conn(utils.TBL_CDRS)
|
||||
defer session.Close()
|
||||
|
||||
@@ -41,7 +41,10 @@ import (
|
||||
)
|
||||
|
||||
func NewCounterGen(limit int64) *CounterGen {
|
||||
return &CounterGen{limit: limit}
|
||||
return &CounterGen{
|
||||
cnt: time.Now().UnixNano(),
|
||||
limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
type CounterGen struct {
|
||||
@@ -53,7 +56,7 @@ func (cg *CounterGen) Gen() int64 {
|
||||
cg.Lock()
|
||||
defer cg.Unlock()
|
||||
cg.cnt += 1
|
||||
if cg.cnt > cg.limit {
|
||||
if cg.limit > 0 && cg.cnt > cg.limit {
|
||||
cg.cnt = 0
|
||||
}
|
||||
return cg.cnt
|
||||
|
||||
Reference in New Issue
Block a user