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

Retry network failures when fetching data from FA #122

Merged
merged 1 commit into from
Mar 15, 2024
Merged
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
23 changes: 23 additions & 0 deletions lib/faexport/scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,8 @@
cookie_str = full_cookie(extra_cookie: extra_cookie, as_guest: as_guest)
raw = @cache.add("url:#{url}:#{cookie_str}") do
start = Time.now
retry_attempts = 0
retry_sleep_time = 0
begin
URI.parse(url).open({ "User-Agent" => USER_AGENT, "Cookie" => "#{cookie_str}" }) do |response|
raise FAStatusError.new(url, response.status.join(" ")) if response.status[0] != "200"
Expand All @@ -1328,8 +1330,29 @@
raise FASlowdownError.new(url)
end
end
# Retry some types of error
if e.io.status[0] == "502" || e.io.status[0] == "520"
retry_attempts += 1
if retry_attempts < 5

Check notice

Code scanning / Rubocop

Check for conditionals that can be replaced with guard clauses. Note

Style/GuardClause: Use a guard clause (raise unless retry_attempts < 5) instead of wrapping the code inside a conditional expression.
sleep(retry_sleep_time)
retry_sleep_time += 0.5
retry
else
raise
end
end
# Raise other HTTP errors as normal
raise
rescue Errno::ECONNRESET => e
# Retry connection reset errors
retry_attempts += 1
if retry_attempts < 5

Check notice

Code scanning / Rubocop

Check for conditionals that can be replaced with guard clauses. Note

Style/GuardClause: Use a guard clause (raise unless retry_attempts < 5) instead of wrapping the code inside a conditional expression.
sleep(retry_sleep_time)
retry_sleep_time += 0.5
retry
else
raise
end
ensure
request_time = Time.now - start
$page_request_time.observe(request_time, labels: { page_type: page_type })
Expand Down
Loading