Skip to content

Commit 5b7e359

Browse files
committed
Cleanups and comments in scheduler.go
1 parent ccc41fd commit 5b7e359

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ruler/scheduler.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ type scheduler struct {
7373
latestConfig configID
7474
latestMutex sync.RWMutex
7575

76-
done chan struct{}
77-
terminated chan struct{}
76+
stop chan struct{}
77+
done chan struct{}
7878
}
7979

8080
// newScheduler makes a new scheduler.
@@ -86,15 +86,15 @@ func newScheduler(configsAPI configsAPI, evaluationInterval, pollInterval time.D
8686
q: NewSchedulingQueue(clockwork.NewRealClock()),
8787
cfgs: map[string]cortexConfig{},
8888

89-
done: make(chan struct{}),
90-
terminated: make(chan struct{}),
89+
stop: make(chan struct{}),
90+
done: make(chan struct{}),
9191
}
9292
}
9393

9494
// Run polls the source of configurations for changes.
9595
func (s *scheduler) Run() {
9696
log.Debugf("Scheduler started")
97-
defer close(s.terminated)
97+
defer close(s.done)
9898
// Load initial set of all configurations before polling for new ones.
9999
s.addNewConfigs(time.Now(), s.loadAllConfigs())
100100
ticker := time.NewTicker(s.pollInterval)
@@ -105,16 +105,17 @@ func (s *scheduler) Run() {
105105
if err != nil {
106106
log.Warnf("Scheduler: error updating configs: %v", err)
107107
}
108-
case <-s.done:
108+
case <-s.stop:
109109
ticker.Stop()
110+
return
110111
}
111112
}
112113
}
113114

114115
func (s *scheduler) Stop() {
115-
close(s.done)
116+
close(s.stop)
116117
s.q.Close()
117-
<-s.terminated
118+
<-s.done
118119
log.Debugf("Scheduler stopped")
119120
}
120121

@@ -186,6 +187,7 @@ func (s *scheduler) addNewConfigs(now time.Time, cfgs map[string]cortexConfigVie
186187
}
187188

188189
func (s *scheduler) addWorkItem(i workItem) {
190+
// The queue is keyed by user ID, so items for existing user IDs will be replaced.
189191
s.q.Enqueue(i)
190192
log.Debugf("Scheduler: work item added: %v", i)
191193
}

0 commit comments

Comments
 (0)