more refactoring on Guardian

This commit is contained in:
Radu Ioan Fericean
2015-07-10 23:33:45 +03:00
parent 0dae4eab28
commit ce2bcac0b9
4 changed files with 9 additions and 9 deletions

View File

@@ -79,7 +79,7 @@ func (self *ApierV1) RemActionTiming(attrs AttrRemActionTiming, reply *string) e
return utils.NewErrMandatoryIeMissing(missing...)
}
}
_, err := engine.AccLock.Guard(func() (interface{}, error) {
_, err := engine.Guardian.Guard(func() (interface{}, error) {
ats, err := self.RatingDb.GetActionPlans(attrs.ActionPlanId)
if err != nil {
return 0, err
@@ -129,7 +129,7 @@ func (self *ApierV1) RemAccountActionTriggers(attrs AttrRemAcntActionTriggers, r
return utils.NewErrMandatoryIeMissing(missing...)
}
balanceId := utils.AccountKey(attrs.Tenant, attrs.Account, attrs.Direction)
_, err := engine.AccLock.Guard(func() (interface{}, error) {
_, err := engine.Guardian.Guard(func() (interface{}, error) {
ub, err := self.AccountDb.GetAccount(balanceId)
if err != nil {
return 0, err
@@ -162,7 +162,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error
balanceId := utils.AccountKey(attr.Tenant, attr.Account, attr.Direction)
var ub *engine.Account
var ats engine.ActionPlans
_, err := engine.AccLock.Guard(func() (interface{}, error) {
_, err := engine.Guardian.Guard(func() (interface{}, error) {
if bal, _ := self.AccountDb.GetAccount(balanceId); bal != nil {
ub = bal
} else { // Not found in db, create it here
@@ -192,7 +192,7 @@ func (self *ApierV1) SetAccount(attr utils.AttrSetAccount, reply *string) error
return utils.NewErrServerError(err)
}
if len(ats) != 0 {
_, err := engine.AccLock.Guard(func() (interface{}, error) { // ToDo: Try locking it above on read somehow
_, err := engine.Guardian.Guard(func() (interface{}, error) { // ToDo: Try locking it above on read somehow
if err := self.RatingDb.SetActionPlans(attr.ActionPlanId, ats); err != nil {
return 0, err
}

View File

@@ -732,7 +732,7 @@ func (self *ApierV1) AddTriggeredAction(attr AttrAddActionTrigger, reply *string
}
tag := utils.AccountKey(attr.Tenant, attr.Account, attr.BalanceDirection)
_, err = engine.AccLock.Guard(func() (interface{}, error) {
_, err = engine.Guardian.Guard(func() (interface{}, error) {
userBalance, err := self.AccountDb.GetAccount(tag)
if err != nil {
return 0, err
@@ -802,7 +802,7 @@ func (self *ApierV1) ResetTriggeredActions(attr AttrResetTriggeredAction, reply
}
}
accID := utils.AccountKey(attr.Tenant, attr.Account, attr.Direction)
_, err := engine.AccLock.Guard(func() (interface{}, error) {
_, err := engine.Guardian.Guard(func() (interface{}, error) {
acc, err := self.AccountDb.GetAccount(accID)
if err != nil {
return 0, err
@@ -829,7 +829,7 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str
return utils.NewErrMandatoryIeMissing("TPid")
}
dbReader := engine.NewTpReader(self.RatingDb, self.AccountDb, self.StorDb, attrs.TPid)
if _, err := engine.AccLock.Guard(func() (interface{}, error) {
if _, err := engine.Guardian.Guard(func() (interface{}, error) {
aas := engine.APItoModelAccountAction(&attrs)
if err := dbReader.LoadAccountActionsFiltered(aas); err != nil {
return 0, err

View File

@@ -71,7 +71,7 @@ func (self *ApierV2) LoadAccountActions(attrs AttrLoadAccountActions, reply *str
tpAa := &utils.TPAccountActions{TPid: attrs.TPid}
tpAa.SetAccountActionsId(attrs.AccountActionsId)
aa := engine.APItoModelAccountAction(tpAa)
if _, err := engine.AccLock.Guard(func() (interface{}, error) {
if _, err := engine.Guardian.Guard(func() (interface{}, error) {
if err := dbReader.LoadAccountActionsFiltered(aa); err != nil {
return 0, err
}

View File

@@ -108,7 +108,7 @@ func (s *Scheduler) LoadActionPlans(storage engine.RatingStorage) {
newAts = append(newAts, at)
}
if toBeSaved {
engine.AccLock.Guard(func() (interface{}, error) {
engine.Guardian.Guard(func() (interface{}, error) {
storage.SetActionPlans(key, newAts)
return 0, nil
}, utils.ACTION_TIMING_PREFIX)