diff --git a/lib/load_routes.go b/lib/load_routes.go index 18f04dd0..51ae561a 100644 --- a/lib/load_routes.go +++ b/lib/load_routes.go @@ -149,9 +149,9 @@ func (rt *Router) listenForContentStoreUpdates(ctx context.Context) error { } func (rt *Router) PeriodicCSRouteUpdates() { - tick := time.Tick(time.Minute) + tick := time.Tick(5 * time.Second) for range tick { - if time.Since(rt.csLastReloadTime) > time.Minute { + if time.Since(rt.csLastAttemptReloadTime) > time.Minute { // This is a non-blocking send, if there is already a notification to reload we don't need to send another one select { case rt.CsReloadChan <- true: @@ -187,6 +187,8 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) { timer.ObserveDuration() }() + rt.csLastAttemptReloadTime = time.Now() + logInfo("router: reloading routes from content store") newmux := triemux.NewMux() @@ -204,5 +206,4 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) { logInfo(fmt.Sprintf("router: reloaded %d routes from content store", routeCount)) routesCountMetric.WithLabelValues("content-store").Set(float64(routeCount)) - } diff --git a/lib/router.go b/lib/router.go index 6109e4ec..fa7baae6 100644 --- a/lib/router.go +++ b/lib/router.go @@ -42,18 +42,18 @@ const ( // come from, Route and Backend should not contain bson fields. // MongoReplicaSet, MongoReplicaSetMember etc. should move out of this module. type Router struct { - backends map[string]http.Handler - mux *triemux.Mux - csMux *triemux.Mux - lock sync.RWMutex - mongoReadToOptime bson.MongoTimestamp - logger logger.Logger - opts Options - ReloadChan chan bool - CsReloadChan chan bool - csMuxSampleRate float64 - csLastReloadTime time.Time - pool *pgxpool.Pool + backends map[string]http.Handler + mux *triemux.Mux + csMux *triemux.Mux + lock sync.RWMutex + mongoReadToOptime bson.MongoTimestamp + logger logger.Logger + opts Options + ReloadChan chan bool + CsReloadChan chan bool + csMuxSampleRate float64 + csLastAttemptReloadTime time.Time + pool *pgxpool.Pool } type Options struct {