module Genesis::RetryingFetcher
Constants
- FETCH_RETRY_INTERVALS
Public Class Methods
get(what, base_url = '', fetch_intervals = FETCH_RETRY_INTERVALS) { |body| ... }
click to toggle source
# File lib/retryingfetcher.rb, line 7 def self.get what, base_url = '', fetch_intervals = FETCH_RETRY_INTERVALS what = File.join(base_url, what) unless base_url.empty? fetch_intervals.each_with_index do |sleep_interval, index| Kernel.sleep(sleep_interval) puts "Fetching '%s' (Attempt #%d)..." % [what, index+1] begin response = HTTParty.get(what) next unless response.code == 200 yield response.body if block_given? return response.body rescue => e puts "RetyingFetcher.get error: %s" % e.message end end nil end