Browse Source

feat(alerting): async exeuction on a shoestring

bergquist 9 years ago
parent
commit
4fce82344e
1 changed files with 7 additions and 2 deletions
  1. 7 2
      pkg/services/alerting/alerting.go

+ 7 - 2
pkg/services/alerting/alerting.go

@@ -76,9 +76,10 @@ func (s *Scheduler) updateJobs(reader RuleReader) {
 	jobs := make([]*AlertJob, 0)
 	rules := reader.Fetch()
 
-	for i := s.serverPosition - 1; i < len(rules); i = i + s.clusterSize {
+	for i := s.serverPosition - 1; i < len(rules); i += s.clusterSize {
 		rule := rules[i]
 		jobs = append(jobs, &AlertJob{
+			id:        rule.Id,
 			name:      rule.Title,
 			frequency: rule.Frequency,
 			rule:      rule,
@@ -150,6 +151,10 @@ type Executor interface {
 type DummieExecutor struct{}
 
 func (this DummieExecutor) Execute(rule m.AlertRule) (err error, result AlertResult) {
-	time.Sleep(1000)
+	if rule.Id == 6 {
+		time.Sleep(time.Second * 60)
+	}
+	time.Sleep(time.Second)
+	log.Info("Finnished executing: %d", rule.Id)
 	return nil, AlertResult{state: "OK", id: rule.Id}
 }