outposts: ensure minimum refresh interval (cherry-pick #10701) (#10702)

outposts: ensure minimum refresh interval (#10701)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Jens L. <jens@goauthentik.io>
This commit is contained in:
gcp-cherry-pick-bot[bot]
2024-07-31 14:59:14 +02:00
committed by GitHub
parent 4ddd4e7f88
commit 6c159d120b

View File

@ -183,7 +183,19 @@ func (ac *APIController) startWSHealth() {
func (ac *APIController) startIntervalUpdater() {
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 {
logger.Debug("Running interval update")
err := ac.OnRefresh()
@ -198,7 +210,7 @@ func (ac *APIController) startIntervalUpdater() {
"build": constants.BUILD("tagged"),
}).SetToCurrentTime()
}
ticker.Reset(time.Duration(ac.Outpost.RefreshIntervalS) * time.Second)
ticker.Reset(getInterval())
}
}