Module: RightSupport::Net::DNS

Defined in:
lib/right_support/net/dns.rb

Class Method Summary collapse

Class Method Details

.resolve_all_ip_addresses(hostnames) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/right_support/net/dns.rb', line 17

def self.resolve_all_ip_addresses(hostnames)
  ips       = []
  hostnames = [hostnames] unless hostnames.respond_to?(:each)
  hostnames.each do |hostname|
    infos = nil
    begin
      infos = Socket.getaddrinfo(hostname, 443, Socket::AF_INET, Socket::SOCK_STREAM, Socket::IPPROTO_TCP)
    rescue Exception => e
      # NOTE: Need to figure out, which logger can we use here?
      # Log.error "Rescued #{e.class.name} resolving Repose hostnames: #{e.message}; retrying"
      retry
    end

    #Randomly permute the addrinfos of each hostname to help spread load.
    infos.shuffle.each do |info|
      ips << info[3]
    end
  end
  ips
end