summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 13:32:59 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-27 13:32:59 +0000
commitff6c540adb5b60b0fd75152434fa67b1fa3d26b7 (patch)
tree2e4602a11f1eef6559ada03149ba5e4fd28fb4ec /tool
parentc46d3de0f547d18b2b69d08fc765344d617ac5b7 (diff)
tool/downloader.rb: retry downloads
because it's randomly failing on CI like https://ci.appveyor.com/project/ruby/ruby/build/1.0.6724 Actually I'm not sure whether the exception class is Errno::ECONNREFUSED or not. Please change the rescued exception to the correct one if it's wrong. I changed to log exception class too in this commit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r--tool/downloader.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/tool/downloader.rb b/tool/downloader.rb
index 335fe97762..c6f6c4701c 100644
--- a/tool/downloader.rb
+++ b/tool/downloader.rb
@@ -161,7 +161,9 @@ class Downloader
$stdout.flush
end
begin
- data = url.read(options.merge(http_options(file, since.nil? ? true : since)))
+ data = with_retry(3, Errno::ECONNREFUSED) do
+ url.read(options.merge(http_options(file, since.nil? ? true : since)))
+ end
rescue OpenURI::HTTPError => http_error
if http_error.message =~ /^304 / # 304 Not Modified
if $VERBOSE
@@ -207,7 +209,7 @@ class Downloader
end
return file.to_path
rescue => e
- raise "failed to download #{name}\n#{e.message}: #{url}"
+ raise "failed to download #{name}\n#{e.class}: #{e.message}: #{url}"
end
def self.under(dir, name)
@@ -264,6 +266,21 @@ class Downloader
end
end
end
+
+ def self.with_retry(max_times, exception, &block)
+ times = 0
+ begin
+ block.call
+ rescue exception => e
+ times += 1
+ if times <= max_times
+ $stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..."
+ sleep(times ** 2)
+ retry
+ end
+ end
+ end
+ private_class_method :with_retry
end
Downloader.https = https.freeze