action timing execution protection

This commit is contained in:
Radu Ioan Fericean
2012-07-09 19:46:17 +03:00
parent ac510fd200
commit 8c53c39214
2 changed files with 8 additions and 5 deletions

View File

@@ -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)
}

View File

@@ -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