lib/relaton_iana/data_fetcher.rb in relaton-iana-1.12.4 vs lib/relaton_iana/data_fetcher.rb in relaton-iana-1.12.5
- old
+ new
@@ -44,13 +44,17 @@
if ENV["GITHUB_TOKEN"]
headers = { "Authorization" => "token #{ENV['GITHUB_TOKEN']}" }
end
attempt = 0
json = {}
+ resp = nil
until attempt > 3 || json["items"]
if attempt.positive?
- warn "Rate limit is reached. Retrying in 30 sec."
- sleep 30
+ t = resp.headers["x-ratelimit-reset"].to_i - Time.now.to_i
+ if t.positive?
+ warn "Rate limit is reached. Retrying in #{t} sec."
+ sleep t
+ end
end
attempt += 1
resp = Faraday.get "https://api.github.com/search/code", params, headers
json = JSON.parse resp.body
end