Skip to content

Instantly share code, notes, and snippets.

@tisba
Created April 1, 2014 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tisba/9913992 to your computer and use it in GitHub Desktop.
Save tisba/9913992 to your computer and use it in GitHub Desktop.
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