ruby-changes:52074
From: k0kubun <ko1@a...>
Date: Sat, 11 Aug 2018 13:22:19 +0900 (JST)
Subject: [ruby-changes:52074] k0kubun:r64282 (trunk): tool/downloader.rb: retry on 502 and 503 error
k0kubun 2018-08-11 13:22:14 +0900 (Sat, 11 Aug 2018) New Revision: 64282 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64282 Log: 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 Modified files: trunk/tool/downloader.rb Index: tool/downloader.rb =================================================================== --- tool/downloader.rb (revision 64281) +++ tool/downloader.rb (revision 64282) @@ -161,7 +161,7 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L161 $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 https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L267 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..." -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/