1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

tool/downloader.rb: retry on 502 and 503 error

rubyci was failed by download 503
https://rubyci.org/logs/rubyci.s3.amazonaws.com/scw-9d6766/ruby-trunk/log/20180811T021706Z.fail.html.gz

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
k0kubun 2018-08-11 04:22:14 +00:00
parent 0f0d7805cb
commit 92c03be888

View file

@ -161,7 +161,7 @@ class Downloader
$stdout.flush
end
begin
data = with_retry(3, [Errno::ETIMEDOUT, SocketError]) do
data = with_retry(3) do
url.read(options.merge(http_options(file, since.nil? ? true : since)))
end
rescue OpenURI::HTTPError => http_error
@ -267,11 +267,12 @@ class Downloader
end
end
def self.with_retry(max_times, exceptions, &block)
def self.with_retry(max_times, &block)
times = 0
begin
block.call
rescue *exceptions => e
rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError => e
raise if e.is_a?(OpenURI::HTTPError) && e.message !~ /^50[23] / # retry only 502, 503 for http error
times += 1
if times <= max_times
$stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..."