From 8c53c39214453139b3892cd7a44301fa96a799c2 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 9 Jul 2012 19:46:17 +0300 Subject: [PATCH] action timing execution protection --- cmd/stress/cgr-balancerstress/cgr-balancerstress.go | 4 ++-- timespans/action_timing.go | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/stress/cgr-balancerstress/cgr-balancerstress.go b/cmd/stress/cgr-balancerstress/cgr-balancerstress.go index 8305b6982..3ed049bef 100644 --- a/cmd/stress/cgr-balancerstress/cgr-balancerstress.go +++ b/cmd/stress/cgr-balancerstress/cgr-balancerstress.go @@ -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) } diff --git a/timespans/action_timing.go b/timespans/action_timing.go index 2708aa6d5..01b4e2be8 100644 --- a/timespans/action_timing.go +++ b/timespans/action_timing.go @@ -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