lib/fozzie/configuration.rb in fozzie-0.0.13 vs lib/fozzie/configuration.rb in fozzie-0.0.14

- old
+ new

@@ -1,19 +1,21 @@ require 'core_ext/hash' require 'resolv' +require 'timeout' module Fozzie # Fozzie configuration allows assignment of global properties # that will be used within the Fozzie codebase. class Configuration - attr_accessor :env, :config_path, :host, :port, :appname, :namespaces + attr_accessor :env, :config_path, :host, :port, :appname, :namespaces, :timeout def initialize(args = {}) merge_and_assign_config(args) - + self.ip_from_host + self.origin_name self end def data_prefix s = [appname, origin_name, env].collect {|s| s.empty? ? nil : s.gsub('.', '-') }.compact.join('.').strip @@ -48,17 +50,22 @@ :host => '127.0.0.1', :port => 8125, :config_path => '', :env => (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'), :appname => '', - :namespaces => %w{Stats S Statistics Warehouse} + :namespaces => %w{Stats S Statistics Warehouse}, + :timeout => 5 }.dup end def host_to_ip return self.host unless self.host.match(ip_address_regex).nil? - ips = Resolv.getaddresses(self.host) - ips.compact.reject {|ip| ip.to_s.match(ip_address_regex).nil? }.first unless ips.nil? + ips = begin + Timeout.timeout(self.timeout) { Resolv.getaddresses(self.host) } + rescue Timeout::Error => exc + [] + end + (ips.empty? ? "" : ips.compact.reject {|ip| ip.to_s.match(ip_address_regex).nil? }.first || "") end def ip_address_regex /^(?:\d{1,3}\.){3}\d{1,3}$/ end \ No newline at end of file