diff --git a/apier/v1/accounts.go b/apier/v1/accounts.go index c6545392b..4496e8bb0 100644 --- a/apier/v1/accounts.go +++ b/apier/v1/accounts.go @@ -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 } diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 22de33b5d..db9728bb0 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -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()