Skip to content

Commit

Permalink
scan fast on first start
Browse files Browse the repository at this point in the history
  • Loading branch information
skandragon committed Jan 19, 2022
1 parent 2f78a4d commit 7adabb4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ func (h *Health) runChecker(checker *healthIndicator) {
// RunCheckers runs all the health checks, one every frequency/count seconds.
func (h *Health) RunCheckers(frequency int) {
nextIndex := 0
h.run = true
firstPass := true // used to ensure we scan fast on first start

h.Lock()
h.run = true
count := len(h.Checks) + 1 // ensure we are at least 1
h.Unlock()

for {
// ensure we sleep while not locked.
sleepDuration := time.Duration(frequency) * time.Second / time.Duration(count)
if firstPass {
sleepDuration = time.Duration(10) * time.Millisecond
}
time.Sleep(sleepDuration)

// locked while manitulating things and calling healthcheck
Expand All @@ -131,6 +135,7 @@ func (h *Health) RunCheckers(frequency int) {
}
if nextIndex >= len(h.Checks) {
nextIndex = 0
firstPass = false
}
h.Unlock()
h.runChecker(&h.Checks[nextIndex])
Expand Down

0 comments on commit 7adabb4

Please sign in to comment.