mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
action timing execution protection
This commit is contained in:
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
//"net/rpc/jsonrpc"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ func main() {
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := timespans.CallCost{}
|
||||
client, err := jsonrpc.Dial("tcp", *balancer)
|
||||
client, err := rpc.Dial("tcp", *balancer)
|
||||
if err != nil {
|
||||
log.Fatalf("could not connect to balancer: %v", err)
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (at *ActionTiming) getUserBalances() (ubs []*UserBalance) {
|
||||
}
|
||||
|
||||
func (at *ActionTiming) Execute() (err error) {
|
||||
// TODO: add sync mutex here
|
||||
|
||||
aac, err := at.getActions()
|
||||
if err != nil {
|
||||
log.Print("Failed to get actions: ", err)
|
||||
@@ -163,8 +163,11 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
return
|
||||
}
|
||||
for _, ub := range at.getUserBalances() {
|
||||
err = actionFunction(ub, a)
|
||||
storageGetter.SetUserBalance(ub)
|
||||
AccLock.Guard(ub.Id, func() (float64, error) {
|
||||
err = actionFunction(ub, a)
|
||||
storageGetter.SetUserBalance(ub)
|
||||
return 0, nil
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user