Skip to content

Commit

Permalink
Merge pull request #21 from Financial-Times/optimize-startup
Browse files Browse the repository at this point in the history
Read the categories once per updateCachedHealth call
  • Loading branch information
tamas-molnar committed Feb 13, 2018
2 parents 9ebd3cf + a30f891 commit 055894b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions cachingController.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ func (c *healthCheckController) collectChecksFromCachesFor(categories map[string

func (c *healthCheckController) updateCachedHealth(services map[string]service, categories map[string]category) {
// adding new services, not touching existing
refreshPeriod := findShortestPeriod(categories)
categories, err := c.healthCheckService.getCategories()
if err != nil {
warnLogger.Printf("Cannot read categories: [%v]\n Using minimum refresh period for services", err)
}
for _, service := range services {
if mService, ok := c.measuredServices[service.name]; !ok || !reflect.DeepEqual(service, c.measuredServices[service.name].service) {
if ok {
mService.cachedHealth.terminate <- true
}
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 {
if categories != nil {
for _, category := range categories {
if isStringInSlice(service.name, category.services) {
refreshPeriod = category.refreshPeriod
Expand Down

0 comments on commit 055894b

Please sign in to comment.