Adds sleep cap to exponential backoff so it does not go too high
This commit is contained in:
parent
31f61d7531
commit
ff70a60fbc
@ -8,6 +8,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const maxTimeout = time.Second * 5
|
||||||
|
|
||||||
type Datasource interface {
|
type Datasource interface {
|
||||||
Fetch() ([]byte, error)
|
Fetch() ([]byte, error)
|
||||||
Type() string
|
Type() string
|
||||||
@ -40,6 +42,10 @@ func getWithExponentialBackoff(url string) (*http.Response, error) {
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
duration := time.Millisecond * time.Duration((math.Pow(float64(2), float64(i)) * 100))
|
duration := time.Millisecond * time.Duration((math.Pow(float64(2), float64(i)) * 100))
|
||||||
|
if duration > maxTimeout {
|
||||||
|
duration = maxTimeout
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("unable to fetch user-data from %s, try again in %s", url, duration)
|
log.Printf("unable to fetch user-data from %s, try again in %s", url, duration)
|
||||||
time.Sleep(duration)
|
time.Sleep(duration)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user