Skip to content

Commit

Permalink
Merge pull request #19 from Financial-Times/respect-cache-refresh-period
Browse files Browse the repository at this point in the history
Take into consideration category refresh period settings
  • Loading branch information
tamas-molnar authored Feb 12, 2018
2 parents b7fb163 + e3f3ed4 commit 9181b39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cachingController.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ func (c *healthCheckController) updateCachedHealth(services map[string]service,
newMService := newMeasuredService(service)
c.measuredServices[service.name] = newMService
refreshPeriod := findShortestPeriod(categories)
categories, err := c.healthCheckService.getCategories()
if err != nil {
warnLogger.Printf("Cannot read categories: [%v]\n Using minimum refresh period for service [%s]", err, service.name)
} else {
for _, category := range categories {
if isStringInSlice(service.name, category.services) {
refreshPeriod = category.refreshPeriod
break
}
}
}
infoLogger.Printf("Scheduling check for service [%s] with refresh period [%v].\n", service.name, refreshPeriod)
go c.scheduleCheck(newMService, refreshPeriod, time.NewTimer(0))
}
}
Expand Down
1 change: 1 addition & 0 deletions controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func TestRemoveAckServiceErr(t *testing.T) {
}

func TestRemoveAckHappyFlow(t *testing.T) {
initLogs(os.Stdout, os.Stdout, os.Stderr)
controller := initializeMockController("test", nil)
err := controller.removeAck(validService)
assert.Nil(t, err)
Expand Down

0 comments on commit 9181b39

Please sign in to comment.