1
0
Fork 0
mirror of https://github.com/Luzifer/rootzone.git synced 2024-11-09 16:30:05 +00:00
rootzone/retry.go
Knut Ahlers 213e724e1b
Add retries to all DNS calls
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-06-22 20:03:17 +02:00

26 lines
342 B
Go

package main
import (
"math"
"time"
)
const (
maxRetries = 5
retryDelay = 1.2
)
func retry(f func() error) error {
var err error
for i := 1; i <= maxRetries; i++ {
if err = f(); err == nil {
return nil
}
sleep := time.Duration(math.Pow(retryDelay, float64(i)) * float64(time.Second))
time.Sleep(sleep)
}
return err
}