Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: 429 Too Many Requests #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/crawler/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func NewCrawler(opt Option) (Crawler, error) {
client := retryablehttp.NewClient()
client.RetryMax = 10
client.Logger = slog.Default()
client.RetryWaitMin = 1 * time.Minute
client.RetryWaitMax = 5 * time.Minute
client.Backoff = retryablehttp.LinearJitterBackoff
client.RetryWaitMin = 1 * time.Second
client.RetryWaitMax = 30 * time.Second
client.Backoff = retryablehttp.DefaultBackoff
client.ResponseLogHook = func(_ retryablehttp.Logger, resp *http.Response) {
if resp.StatusCode != http.StatusOK {
slog.Warn("Unexpected http response", slog.String("url", resp.Request.URL.String()), slog.String("status", resp.Status))
Expand Down Expand Up @@ -430,7 +430,15 @@ func (c *Crawler) httpGet(ctx context.Context, url string) (*http.Response, erro
if err != nil {
return nil, xerrors.Errorf("unable to create a HTTP request: %w", err)
}
resp, err := c.http.Do(req)

// Set up exponential backoff
client := retryablehttp.NewClient()
client.RetryMax = 5
client.RetryWaitMin = 1 * time.Second
client.RetryWaitMax = 30 * time.Second
client.Backoff = retryablehttp.DefaultBackoff

resp, err := client.Do(req)
if err != nil {
return nil, xerrors.Errorf("http error (%s): %w", url, err)
}
Expand Down