diff --git a/cmd/cgr-rater/cgr-rater.go b/cmd/cgr-rater/cgr-rater.go index 0342d58ad..d4a4aff46 100644 --- a/cmd/cgr-rater/cgr-rater.go +++ b/cmd/cgr-rater/cgr-rater.go @@ -414,8 +414,8 @@ func main() { timespans.Logger.Info("Starting CGRateS scheduler.") go func() { sched := scheduler.NewScheduler() - sched.LoadActionTimings(getter) go reloadSchedulerSingnalHandler(sched, getter) + sched.LoadActionTimings(getter) sched.Loop() }() } diff --git a/cmd/cgr-rater/registration.go b/cmd/cgr-rater/registration.go index 6f55b87a7..bf452d416 100644 --- a/cmd/cgr-rater/registration.go +++ b/cmd/cgr-rater/registration.go @@ -99,7 +99,6 @@ func registerToBalancer() { func reloadSchedulerSingnalHandler(sched *scheduler.Scheduler, getter timespans.DataStorage) { timespans.Logger.Info("Handling HUP signal...") for { - timespans.Logger.Debug("here again") c := make(chan os.Signal) signal.Notify(c, syscall.SIGHUP) sig := <-c diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 2977895e5..cb1d0d0ef 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -78,7 +78,7 @@ func (s *Scheduler) LoadActionTimings(storage timespans.DataStorage) { isAsap = at.CheckForASAP() toBeSaved = toBeSaved || isAsap if at.IsOneTimeRun() { - timespans.Logger.Info(fmt.Sprintf("Time for one time action on %v", at)) + timespans.Logger.Info(fmt.Sprintf("Time for one time action on %v", key)) go at.Execute() // do not append it to the newAts list to be saved } else { diff --git a/timespans/action.go b/timespans/action.go index dc8f2cc02..d19290aaf 100644 --- a/timespans/action.go +++ b/timespans/action.go @@ -128,8 +128,10 @@ func resetCountersAction(ub *UserBalance, a *Action) (err error) { } func genericMakeNegative(a *Action) { - a.Units = -a.Units - if a.MinuteBucket != nil { + if a.Units > 0 { // only apply if not allready negative + a.Units = -a.Units + } + if a.MinuteBucket != nil && a.MinuteBucket.Seconds > 0 { a.MinuteBucket.Seconds = -a.MinuteBucket.Seconds } } diff --git a/timespans/action_timing.go b/timespans/action_timing.go index efdcc59eb..b8b829a34 100644 --- a/timespans/action_timing.go +++ b/timespans/action_timing.go @@ -56,7 +56,7 @@ func (at *ActionTiming) GetNextStartTime() (t time.Time) { now := time.Now() y, m, d := now.Date() z, _ := now.Zone() - if i.StartTime != "" { + if i.StartTime != "" && i.StartTime != ASAP { l := fmt.Sprintf("%d-%d-%d %s %s", y, m, d, i.StartTime, z) var err error t, err = time.Parse(FORMAT, l) @@ -219,7 +219,7 @@ func (at *ActionTiming) Execute() (err error) { } for _, ub := range at.getUserBalances() { AccLock.Guard(ub.Id, func() (float64, error) { - go Logger.Info(fmt.Sprintf("Executing %v: %v", ub.Id, a)) + Logger.Info(fmt.Sprintf("Executing %v on %v", a.ActionType, ub.Id)) err = actionFunction(ub, a) storageGetter.SetUserBalance(ub) return 0, nil diff --git a/timespans/actions_test.go b/timespans/actions_test.go index 8b49ed48e..06e62b874 100644 --- a/timespans/actions_test.go +++ b/timespans/actions_test.go @@ -816,6 +816,18 @@ func TestActionTimingLogging(t *testing.T) { } } +func TestActionMakeNegative(t *testing.T) { + a := &Action{Units: 10} + genericMakeNegative(a) + if a.Units > 0 { + t.Error("Failed to make negative: ", a) + } + genericMakeNegative(a) + if a.Units > 0 { + t.Error("Failed to preserve negative: ", a) + } +} + /********************************** Benchmarks ********************************/ func BenchmarkUUID(b *testing.B) {