mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
better make negative and logging for action timings
This commit is contained in:
@@ -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()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user