Skip to content

Commit

Permalink
Fix: use Golang style
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Vrba committed Feb 16, 2024
1 parent 97cce99 commit 551cb3c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pkg/reg/adapter/dockerhub/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func getAdapterInfo() *model.AdapterPattern {
//
// so it is better to not hit the wall.
func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*http.Response, error) {
var attempts_left int = 3
for attempts_left > 0 {
var attemptsLeft = 3
for attemptsLeft > 0 {
resp, err := a.client.Do(method, path, body)
if err != nil {
return resp, err
Expand All @@ -149,24 +149,23 @@ func (a *adapter) limitAwareDo(method string, path string, body io.Reader) (*htt
time.Sleep(time.Duration(seconds * 1000 * 1000 * 1000))
log.Info("Sleep finished, resuming operation")
} else {
remaining_req, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-remaining"), 10, 64)
reqsLeft, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-remaining"), 10, 64)
if err != nil {
return resp, err
}
if remaining_req < 8 {
reset_at, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-reset"), 10, 64)
if reqsLeft < 8 {
resetTSC, err := strconv.ParseInt(resp.Header.Get("x-ratelimit-reset"), 10, 64)
if err != nil {
return resp, err
}
seconds := reset_at - time.Now().Unix()
seconds := resetTSC - time.Now().Unix()
log.Infof("Ratelimit exhaustion eminent, sleeping for %d seconds", seconds)
time.Sleep(time.Duration(seconds * 1000 * 1000 * 1000))
log.Info("Sleep finished, resuming operation")

}
return resp, err
}
attempts_left--
attemptsLeft--
}
return nil, errors.New("unable to get past dockerhub rate-limit")
}
Expand Down

0 comments on commit 551cb3c

Please sign in to comment.