Reuse backoff waiting code for errors during GeoIP update.

This commit is contained in:
Joachim Bauch 2024-02-27 16:15:42 +01:00
parent f6fe960534
commit a68454ceec
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02

15
hub.go
View file

@ -417,19 +417,20 @@ func (h *Hub) updateGeoDatabase() {
}
defer h.geoipUpdating.Store(false)
delay := time.Second
backoff, err := NewExponentialBackoff(time.Second, 5*time.Minute)
if err != nil {
log.Printf("Could not create exponential backoff: %s", err)
return
}
for !h.closer.IsClosed() {
err := h.geoip.Update()
if err == nil {
break
}
log.Printf("Could not update GeoIP database, will retry later (%s)", err)
time.Sleep(delay)
delay = delay * 2
if delay > 5*time.Minute {
delay = 5 * time.Minute
}
log.Printf("Could not update GeoIP database, will retry in %s (%s)", backoff.NextWait(), err)
backoff.Wait(context.Background())
}
}