diff --git a/cmd/cgr-scheduler/cgr-scheduler.go b/cmd/cgr-scheduler/cgr-scheduler.go index 42909df03..0c00de108 100644 --- a/cmd/cgr-scheduler/cgr-scheduler.go +++ b/cmd/cgr-scheduler/cgr-scheduler.go @@ -63,7 +63,7 @@ func (s scheduler) loop() { a0 := s.queue[0] now := time.Now() if a0.GetNextStartTime().Equal(now) || a0.GetNextStartTime().Before(now) { - a0.Execute() + go a0.Execute() s.queue = append(s.queue, a0) s.queue = s.queue[1:] sort.Sort(s.queue) diff --git a/timespans/actions.go b/timespans/actions.go index 6f1fd6935..78b1bae9e 100644 --- a/timespans/actions.go +++ b/timespans/actions.go @@ -74,6 +74,19 @@ type Action struct { MinuteBucket *MinuteBucket } +type actionTypeFunc func(a *Action) error + +var ( + actionTypeFuncMap = map[string]actionTypeFunc{ + "LOG": logAction, + } +) + +func logAction(a *Action) (err error) { + log.Printf("%v %v %v", a.BalanceId, a.Units, a.MinuteBucket) + return +} + // Structure to store actions according to weight type actionsorter []*Action @@ -202,12 +215,18 @@ MONTHS: return } -func (at *ActionTiming) Execute() { +func (at *ActionTiming) Execute() (err error) { aac, err := at.getActions() if err != nil { return } for _, a := range aac { - log.Print(a) + actionFunction, exists := actionTypeFuncMap[a.ActionType] + if !exists { + log.Printf("Function type %v not available, aborting execution!", a.ActionType) + return + } + err = actionFunction(a) } + return } diff --git a/timespans/actions_test.go b/timespans/actions_test.go index 0f5aafd27..cba21957d 100644 --- a/timespans/actions_test.go +++ b/timespans/actions_test.go @@ -161,3 +161,19 @@ func TestActionTimingHourMonthdaysMonths(t *testing.T) { t.Errorf("Expected %v was %v", expected, st) } } + +func TestLogFunction(t *testing.T) { + a := &Action{ + ActionType: "LOG", + BalanceId: "test", + Units: 1.1, + MinuteBucket: &MinuteBucket{}, + } + at := &ActionTiming{ + actions: []*Action{a}, + } + err := at.Execute() + if err != nil { + t.Errorf("Could not execute LOG action: %v", err) + } +} diff --git a/timespans/userbalance.go b/timespans/userbalance.go index c8ea605c6..5ce238283 100644 --- a/timespans/userbalance.go +++ b/timespans/userbalance.go @@ -30,10 +30,11 @@ const ( INBOUND = "IN" OUTBOUND = "OUT" // Balance types - CREDIT = "MONETARY" - SMS = "SMS" - TRAFFIC = "INTERNET" - MINUTES = "MINUTES" + CREDIT = "MONETARY" + SMS = "SMS" + TRAFFIC = "INTERNET" + TRAFFIC_TIME = "INTERNET_TIME" + MINUTES = "MINUTES" // Price types PERCENT = "PERCENT" ABSOLUTE = "ABSOLUTE"