@@ -289,38 +289,47 @@ func runStaticSecretsRefresh(cache *Cache, domainURL *url.URL, httpClient *http.
289289 Msg ("Static secrets refresh completed" )
290290}
291291
292- // StartBackgroundLoops starts the background loops for token validation and secrets refresh.
293- // When sseEnabled is true, the static secrets refresh loop is disabled (SSE handles cache invalidation).
294- func StartBackgroundLoops (ctx context.Context , cache * Cache , domainURL * url.URL , httpClient * http.Client , evictionStrategy string , accessTokenCheckInterval time.Duration , staticSecretsRefreshInterval time.Duration , sseEnabled bool ) {
292+ func startAccessTokenValidation (ctx context.Context , cache * Cache , domainURL * url.URL , httpClient * http.Client , accessTokenCheckInterval time.Duration ) {
295293 tokenTicker := time .NewTicker (accessTokenCheckInterval )
296294 defer tokenTicker .Stop ()
297295
298- var secretsTickerC <- chan time.Time
299- if ! sseEnabled {
300- secretsTicker := time .NewTicker (staticSecretsRefreshInterval )
301- defer secretsTicker .Stop ()
302- secretsTickerC = secretsTicker .C
303- } else {
304- secretsTickerC = make (chan time.Time )
305- log .Info ().Msg ("Static secrets refresh disabled (SSE mode active)" )
296+ for {
297+ select {
298+ case <- tokenTicker .C :
299+ runAccessTokenValidation (cache , domainURL , httpClient )
300+ case <- ctx .Done ():
301+ return
302+ }
306303 }
304+ }
307305
308- log .Info ().
309- Str ("evictionStrategy" , evictionStrategy ).
310- Str ("accessTokenCheckInterval" , accessTokenCheckInterval .String ()).
311- Str ("staticSecretsRefreshInterval" , staticSecretsRefreshInterval .String ()).
312- Bool ("sseEnabled" , sseEnabled ).
313- Msg ("Background loops started" )
306+ func startStaticSecretsRefresh (ctx context.Context , cache * Cache , domainURL * url.URL , httpClient * http.Client , staticSecretsRefreshInterval time.Duration ) {
307+ secretsTicker := time .NewTicker (staticSecretsRefreshInterval )
308+ defer secretsTicker .Stop ()
314309
315310 for {
316311 select {
317- case <- tokenTicker .C :
318- runAccessTokenValidation (cache , domainURL , httpClient )
319- case <- secretsTickerC :
312+ case <- secretsTicker .C :
320313 runStaticSecretsRefresh (cache , domainURL , httpClient , staticSecretsRefreshInterval )
321314 case <- ctx .Done ():
322- log .Info ().Msg ("Background loops stopped" )
323315 return
324316 }
325317 }
326318}
319+
320+ // StartBackgroundLoops starts the background loops for token validation and secrets refresh.
321+ // When sseEnabled is true, the static secrets refresh loop is disabled (SSE handles cache invalidation).
322+ func StartBackgroundLoops (ctx context.Context , cache * Cache , domainURL * url.URL , httpClient * http.Client , evictionStrategy string , accessTokenCheckInterval time.Duration , staticSecretsRefreshInterval time.Duration , sseEnabled bool ) {
323+ log .Info ().
324+ Str ("evictionStrategy" , evictionStrategy ).
325+ Str ("accessTokenCheckInterval" , accessTokenCheckInterval .String ()).
326+ Str ("staticSecretsRefreshInterval" , staticSecretsRefreshInterval .String ()).
327+ Bool ("sseEnabled" , sseEnabled ).
328+ Msg ("Background loops started" )
329+
330+ if sseEnabled {
331+ go startAccessTokenValidation (ctx , cache , domainURL , httpClient , accessTokenCheckInterval )
332+ }
333+ go startStaticSecretsRefresh (ctx , cache , domainURL , httpClient , staticSecretsRefreshInterval )
334+
335+ }
0 commit comments