Commit f6567816 authored by ale's avatar ale

Minor fix to google books ratelimit response

parent a5e06fb5
Pipeline #455 passed with stages
in 1 minute and 24 seconds
...@@ -126,9 +126,11 @@ func googleBooksGet(uri string) (*http.Response, error) { ...@@ -126,9 +126,11 @@ func googleBooksGet(uri string) (*http.Response, error) {
<-gbSemaphore <-gbSemaphore
}() }()
// Set a deadline to 1 hour. // Set a deadline to 10 minutes.
timeout := 900 * time.Second
backoff := 500 * time.Millisecond backoff := 500 * time.Millisecond
deadline := time.Now().Add(3600 * time.Second) maxBackoff := 60 * time.Second
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) { for time.Now().Before(deadline) {
resp, err := http.Get(uri) resp, err := http.Get(uri)
if err != nil { if err != nil {
...@@ -140,6 +142,9 @@ func googleBooksGet(uri string) (*http.Response, error) { ...@@ -140,6 +142,9 @@ func googleBooksGet(uri string) (*http.Response, error) {
resp.Body.Close() resp.Body.Close()
time.Sleep(backoff) time.Sleep(backoff)
backoff += backoff / 2 backoff += backoff / 2
if backoff > maxBackoff {
backoff = maxBackoff
}
continue continue
case 200: case 200:
return resp, nil return resp, nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment