From 115fe8a1ade317c9ed867b156636b8ab8a0e92fc Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Fri, 18 Dec 2015 17:48:03 +0200 Subject: [PATCH] write tasks on loadaccountactions --- apier/v1/apier.go | 2 +- engine/tp_reader.go | 15 +++++++++++++++ scheduler/scheduler.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/apier/v1/apier.go b/apier/v1/apier.go index e1e4e7bfb..140c6eb1c 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -806,7 +806,7 @@ func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *str } // ToDo: Get the action keys loaded by dbReader so we reload only these in cache // Need to do it before scheduler otherwise actions to run will be unknown - if err := self.RatingDb.CacheRatingPrefixes(utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.SHARED_GROUP_PREFIX); err != nil { + if err := self.RatingDb.CacheRatingPrefixes(utils.DERIVEDCHARGERS_PREFIX, utils.ACTION_PREFIX, utils.SHARED_GROUP_PREFIX, utils.ACTION_PLAN_PREFIX); err != nil { return err } if self.Sched != nil { diff --git a/engine/tp_reader.go b/engine/tp_reader.go index d5d4fc4a5..8012e7ad0 100644 --- a/engine/tp_reader.go +++ b/engine/tp_reader.go @@ -732,6 +732,21 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error actionPlan.AccountIDs = exitingAccountIds } + // write tasks + for _, at := range actionPlan.ActionTimings { + if at.IsASAP() { + for accID := range actionPlan.AccountIDs { + t := &Task{ + Uuid: utils.GenUUID(), + AccountID: accID, + ActionsID: at.ActionsID, + } + if err = tpr.ratingStorage.PushTask(t); err != nil { + return err + } + } + } + } // write action plan err = tpr.ratingStorage.SetActionPlan(accountAction.ActionPlanId, actionPlan) if err != nil { diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 30afa0814..e8c6896a9 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -96,7 +96,7 @@ func (s *Scheduler) loadActionPlans() { s.Lock() defer s.Unlock() // limit the number of concurrent tasks - var limit = make(chan bool, 10) + limit := make(chan bool, 10) // execute existing tasks for { task, err := s.storage.PopTask()