Class: DNSLoadBalancer
- Inherits:
-
Object
- Object
- DNSLoadBalancer
- Defined in:
- lib/dns-loadbalancer.rb
Instance Attribute Summary collapse
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(hosts, port, verbose: true) ⇒ DNSLoadBalancer
constructor
A new instance of DNSLoadBalancer.
- #run ⇒ Object
Constructor Details
#initialize(hosts, port, verbose: true) ⇒ DNSLoadBalancer
Returns a new instance of DNSLoadBalancer.
8 9 10 11 12 |
# File 'lib/dns-loadbalancer.rb', line 8 def initialize(hosts, port, verbose: true) @hosts = hosts.split(',') @port = port @verbose = verbose end |
Instance Attribute Details
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/dns-loadbalancer.rb', line 6 def hosts @hosts end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/dns-loadbalancer.rb', line 6 def port @port end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dns-loadbalancer.rb', line 14 def run start = Time.now ip_addresses = hosts.flat_map do |h| result = resolve(h) log "Resolved #{h} to IP addresses: #{result}" result end result = find_closest(ip_addresses) log "Found fastest IP #{result} in #{(Time.now - start).round(2)}s" result end |