Skip to content
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 @@ def fetch(path, extra_cookie = nil, as_guest: false)
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 @@ def fetch(path, extra_cookie = nil, as_guest: false)
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.

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.

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