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:
parent
0f0d7805cb
commit
92c03be888
1 changed files with 4 additions and 3 deletions
|
@ -161,7 +161,7 @@ class Downloader
|
||||||
$stdout.flush
|
$stdout.flush
|
||||||
end
|
end
|
||||||
begin
|
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)))
|
url.read(options.merge(http_options(file, since.nil? ? true : since)))
|
||||||
end
|
end
|
||||||
rescue OpenURI::HTTPError => http_error
|
rescue OpenURI::HTTPError => http_error
|
||||||
|
@ -267,11 +267,12 @@ class Downloader
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.with_retry(max_times, exceptions, &block)
|
def self.with_retry(max_times, &block)
|
||||||
times = 0
|
times = 0
|
||||||
begin
|
begin
|
||||||
block.call
|
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
|
times += 1
|
||||||
if times <= max_times
|
if times <= max_times
|
||||||
$stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..."
|
$stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..."
|
||||||
|
|
Loading…
Add table
Reference in a new issue