Skip to content

Commit

Permalink
Really retry when fetching collection pages, which error a lot
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
lmullen committed Aug 18, 2021
1 parent 92f2aca commit 4062e70
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crawler/collection-pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (c Collection) FetchCollectionItems(page int, results chan<- CollectionAPIP
return
}

attempt := 1

fetch:
// Limit the rate
app.Limiters.Collections.Take()

Expand All @@ -57,13 +60,27 @@ func (c Collection) FetchCollectionItems(page int, results chan<- CollectionAPIP
"url": url,
}).Warn("HTTP error when fetching from API")
quitIfBlocked(response.StatusCode)
return
if attempt <= 6 {
log.WithField("url", url).WithField("attempt", attempt).
Warn("Retrying this page of results because of error: ", err)
attempt++
goto fetch
} else {
return
}
}

data, err := io.ReadAll(response.Body)
if err != nil {
log.WithField("url", url).Warn("Error reading HTTP response body: ", err)
return
if attempt <= 10 {
log.WithField("url", url).WithField("attempt", attempt).
Warn("Retrying this page of results because of error: ", err)
attempt++
goto fetch
} else {
return
}
}

var result CollectionAPIPage
Expand Down

0 comments on commit 4062e70

Please sign in to comment.