clean action plans on account remove

This commit is contained in:
Radu Ioan Fericean
2015-11-11 12:38:01 +02:00
parent 93af13112a
commit 86939cfec0
2 changed files with 27 additions and 2 deletions

View File

@@ -231,6 +231,31 @@ func (self *ApierV1) RemoveAccount(attr utils.AttrRemoveAccount, reply *string)
}
accountId := utils.AccountKey(attr.Tenant, attr.Account)
_, err := engine.Guardian.Guard(func() (interface{}, error) {
// remove it from all action plans
allATs, err := self.RatingDb.GetAllActionPlans()
if err != nil && err != utils.ErrNotFound {
return 0, err
}
for key, ats := range allATs {
changed := false
for _, at := range ats {
for i := 0; i < len(at.AccountIds); i++ {
if at.AccountIds[i] == accountId {
// delete without preserving order
at.AccountIds[i] = at.AccountIds[len(at.AccountIds)-1]
at.AccountIds = at.AccountIds[:len(at.AccountIds)-1]
i -= 1
changed = true
}
}
}
if changed {
// save action plan
self.RatingDb.SetActionPlans(key, ats)
// cache
self.RatingDb.CacheRatingPrefixValues(map[string][]string{utils.ACTION_PLAN_PREFIX: []string{utils.ACTION_PLAN_PREFIX + key}})
}
}
if err := self.AccountDb.RemoveAccount(accountId); err != nil {
return 0, err
}

View File

@@ -81,8 +81,8 @@ func (s *Scheduler) Loop() {
func (s *Scheduler) LoadActionPlans(storage engine.RatingStorage) {
actionPlans, err := storage.GetAllActionPlans()
if err != nil {
//utils.Logger.Warning(fmt.Sprintf("Cannot get action plans: %v", err))
if err != nil && err != utils.ErrNotFound {
utils.Logger.Warning(fmt.Sprintf("Cannot get action plans: %v", err))
}
// recreate the queue
s.Lock()