outposts: ensure minimum refresh interval (#10701)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2024-07-31 14:43:03 +02:00
committed by GitHub
parent abfc48e00e
commit 9b595b2031

View File

@ -183,7 +183,19 @@ func (ac *APIController) startWSHealth() {
func (ac *APIController) startIntervalUpdater() { func (ac *APIController) startIntervalUpdater() {
logger := ac.logger.WithField("loop", "interval-updater") logger := ac.logger.WithField("loop", "interval-updater")
ticker := time.NewTicker(time.Duration(ac.Outpost.RefreshIntervalS) * time.Second) getInterval := func() time.Duration {
// Ensure timer interval is not negative or 0
// for 0 we assume migration or unconfigured, so default to 5 minutes
if ac.Outpost.RefreshIntervalS <= 0 {
return 5 * time.Minute
}
// Clamp interval to be at least 30 seconds
if ac.Outpost.RefreshIntervalS < 30 {
return 30 * time.Second
}
return time.Duration(ac.Outpost.RefreshIntervalS) * time.Second
}
ticker := time.NewTicker(getInterval())
for ; true; <-ticker.C { for ; true; <-ticker.C {
logger.Debug("Running interval update") logger.Debug("Running interval update")
err := ac.OnRefresh() err := ac.OnRefresh()
@ -198,7 +210,7 @@ func (ac *APIController) startIntervalUpdater() {
"build": constants.BUILD("tagged"), "build": constants.BUILD("tagged"),
}).SetToCurrentTime() }).SetToCurrentTime()
} }
ticker.Reset(time.Duration(ac.Outpost.RefreshIntervalS) * time.Second) ticker.Reset(getInterval())
} }
} }