diff --git a/ci/pulse/api/lib/pulse_build_result.rb b/ci/pulse/api/lib/pulse_build_result.rb index 36f4d9f6bb3b7954a1d9655d57ed466a65b39333..b76e2739d4d6e50d622159a709cbc686061edcd9 100644 --- a/ci/pulse/api/lib/pulse_build_result.rb +++ b/ci/pulse/api/lib/pulse_build_result.rb @@ -2,6 +2,7 @@ require "net/http" require "uri" class PulseBuildResult + MAX_RETRY_ATTEMPTS = 3 def initialize(pulse_options, build_result, build_messages, build_artifacts) @pulse_options = pulse_options @@ -51,7 +52,7 @@ class PulseBuildResult def fetch_uri(uri_string, limit = 10) raise ArgumentError, 'HTTP redirect too deep' if limit == 0 - response = Net::HTTP.get_response(URI.parse(uri_string)) + response = retry_call { Net::HTTP.get_response(URI.parse(uri_string)) } case response when Net::HTTPSuccess then response when Net::HTTPRedirection then fetch_uri(response['location'], limit - 1) @@ -60,6 +61,19 @@ class PulseBuildResult end end + def retry_call(&block) + attempts = 0 + begin + yield + rescue Net::HTTPFatalError => error + raise error if attempts > MAX_RETRY_ATTEMPTS + puts "Got error: #{error} - retry ##{attempts} of #{MAX_RETRY_ATTEMPTS}" + attempts += 1 + sleep (10 * attempts) + retry + end + end + def colorize(message) colors = { :red => 31,