mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
keep even the asap actionplans for future refernce
This commit is contained in:
@@ -296,6 +296,9 @@ func (at *ActionPlan) Execute() (err error) {
|
||||
}
|
||||
|
||||
func (at *ActionPlan) IsASAP() bool {
|
||||
if at.Timing == nil {
|
||||
return false
|
||||
}
|
||||
return at.Timing.Timing.StartTime == utils.ASAP
|
||||
}
|
||||
|
||||
|
||||
@@ -571,7 +571,7 @@ func (tpr *TpReader) LoadActionPlans() (err error) {
|
||||
if !exists {
|
||||
return fmt.Errorf("[ActionPlans] Could not load the timing for tag: %v", at.TimingId)
|
||||
}
|
||||
actTmg := &ActionPlan{
|
||||
actPln := &ActionPlan{
|
||||
Uuid: utils.GenUUID(),
|
||||
Id: atId,
|
||||
Weight: at.Weight,
|
||||
@@ -586,7 +586,7 @@ func (tpr *TpReader) LoadActionPlans() (err error) {
|
||||
},
|
||||
ActionsId: at.ActionsId,
|
||||
}
|
||||
tpr.actionPlans[atId] = append(tpr.actionPlans[atId], actTmg)
|
||||
tpr.actionPlans[atId] = append(tpr.actionPlans[atId], actPln)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +694,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
} else {
|
||||
t = tpr.timings[at.TimingId] // *asap
|
||||
}
|
||||
actTmg := &ActionPlan{
|
||||
actPln := &ActionPlan{
|
||||
Uuid: utils.GenUUID(),
|
||||
Id: accountAction.ActionPlanId,
|
||||
Weight: at.Weight,
|
||||
@@ -709,7 +709,7 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
ActionsId: at.ActionsId,
|
||||
}
|
||||
// collect action ids from timings
|
||||
actionsIds = append(actionsIds, actTmg.ActionsId)
|
||||
actionsIds = append(actionsIds, actPln.ActionsId)
|
||||
//add user balance id if no already in
|
||||
found := false
|
||||
for _, ubId := range exitingAccountIds {
|
||||
@@ -719,9 +719,9 @@ func (tpr *TpReader) LoadAccountActionsFiltered(qriedAA *TpAccountAction) error
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
actTmg.AccountIds = append(exitingAccountIds, id)
|
||||
actPln.AccountIds = append(exitingAccountIds, id)
|
||||
}
|
||||
actionTimings = append(actionTimings, actTmg)
|
||||
actionTimings = append(actionTimings, actPln)
|
||||
}
|
||||
|
||||
// write action triggers
|
||||
@@ -1503,7 +1503,7 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
|
||||
i++
|
||||
}
|
||||
return keys, nil
|
||||
case utils.ACTION_PREFIX: // actionPlans
|
||||
case utils.ACTION_PREFIX:
|
||||
keys := make([]string, len(tpr.actions))
|
||||
i := 0
|
||||
for k := range tpr.actions {
|
||||
|
||||
@@ -20,6 +20,7 @@ package scheduler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -87,32 +88,35 @@ func (s *Scheduler) LoadActionPlans(storage engine.RatingStorage) {
|
||||
// recreate the queue
|
||||
s.Lock()
|
||||
s.queue = engine.ActionPlanPriotityList{}
|
||||
for key, ats := range actionPlans {
|
||||
for key, aps := range actionPlans {
|
||||
toBeSaved := false
|
||||
isAsap := false
|
||||
newApls := make([]*engine.ActionPlan, 0) // will remove the one time runs from the database
|
||||
for _, at := range ats {
|
||||
isAsap = at.IsASAP()
|
||||
for _, ap := range aps {
|
||||
log.Printf("AP %+v", ap)
|
||||
isAsap = ap.IsASAP()
|
||||
toBeSaved = toBeSaved || isAsap
|
||||
if isAsap {
|
||||
if len(at.AccountIds) > 0 {
|
||||
if len(ap.AccountIds) > 0 {
|
||||
engine.Logger.Info(fmt.Sprintf("Time for one time action on %v", key))
|
||||
}
|
||||
at.Execute()
|
||||
at.AccountIds = make([]string, 0)
|
||||
// do not append it to the newApls list to be saved
|
||||
ap.Execute()
|
||||
ap.AccountIds = make([]string, 0)
|
||||
} else {
|
||||
now := time.Now()
|
||||
if at.GetNextStartTime(now).Before(now) {
|
||||
if ap.GetNextStartTime(now).Before(now) {
|
||||
// the task is obsolete, do not add it to the queue
|
||||
continue
|
||||
}
|
||||
s.queue = append(s.queue, at)
|
||||
s.queue = append(s.queue, ap)
|
||||
}
|
||||
// save even asap action plans with empty account id list
|
||||
newApls = append(newApls, at)
|
||||
newApls = append(newApls, ap)
|
||||
}
|
||||
if toBeSaved {
|
||||
for _, ap := range newApls {
|
||||
log.Printf("NewAP: %+v", ap)
|
||||
}
|
||||
engine.Guardian.Guard(func() (interface{}, error) {
|
||||
storage.SetActionPlans(key, newApls)
|
||||
return 0, nil
|
||||
|
||||
Reference in New Issue
Block a user