class GenericDownloader
Public Class Methods
Source
# File lib/cartocss_helper/util/generic_downloader.rb, line 22 def initialize(timeout: 20, error_message: nil, stop_on_timeout: true, wrapper: RestClientWrapper.new) @request_timeout = timeout @retry_count = 0 @error_message = error_message @stop_on_timeout = stop_on_timeout @wrapper = wrapper end
Public Instance Methods
Source
# File lib/cartocss_helper/util/generic_downloader.rb, line 55 def get_specified_resource(url, description: nil) Log.info description if description return @wrapper.fetch_data_from_url(url, @request_timeout) rescue ExceptionWithResponse => e output_shared_error_part(url, e) Log.warn e.response Log.warn e.http_code if retry_allowed(e) get_specified_resource(url) else raise e end rescue ExceptionWithoutResponse => e output_shared_error_part(url, e) raise e end
Source
# File lib/cartocss_helper/util/generic_downloader.rb, line 30 def max_retry_count 5 end
Source
# File lib/cartocss_helper/util/generic_downloader.rb, line 43 def retry_allowed(exception_with_response) raise exception_with_response if @retry_count > max_retry_count if @stop_on_timeout raise exception_with_response if exception_with_response.is_a?(RequestTimeout) end if [429, 503, 504].include?(exception_with_response.http_code) @retry_count += 1 return true end raise exception_with_response end