Created
April 1, 2014 13:30
-
-
Save tisba/9913992 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connect_with_retry(&block) | |
hosts = @hosts.dup | |
delay = @initial_delay | |
begin | |
hosts.push(host = hosts.shift) | |
http = Net::HTTP.new(host, @port) | |
http.open_timeout = @open_timeout | |
http.read_timeout = @read_timeout | |
http.use_ssl = @use_ssl | |
block.call(http) | |
rescue InfluxDB::Error | |
rescue StandardError => e | |
log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s." | |
log :info, "Queue size is #{@queue.length}." unless @queue.nil? | |
sleep delay | |
delay = [@max_delay, delay * 2].min | |
retry | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment