lib/deputy.rb in deputy-0.1.56 vs lib/deputy.rb in deputy-0.1.57

- old
+ new

@@ -6,11 +6,11 @@ def eval_and_fetch_constants(x) old = Module.constants.map{|c| c.to_s} begin eval(x) rescue Exception => e - raise e unless Deputy.config['silent_on_errors'] + raise e unless Deputy.config['silent_on_errors'] end new = (Module.constants.map{|c| c.to_s} - old) new = new.select{|c| c.to_s =~ /^TEMP/ } # do not fetch required libs, just user-defined new.map{|c| const_get(c) } end @@ -106,11 +106,11 @@ def self.run_plugins(options={}) return if config['disabled'] start_time = Time.now.to_i sleep_random_interval unless options[:no_wait] - content = get("/plugins.rb") + content = get("/plugins.rb", options) exceptions = [] Scout.plugins(content).each do |interval, plugin| wait = minutes_to_wait(start_time, interval) if wait == 0 @@ -144,30 +144,39 @@ return if config['disabled'] url = "#{sheriff_url}#{path}" url = "http://#{url}" unless url =~ %r{://} options[:http_basic_authentication] = extract_auth_from_url!(url) url = add_host_to_url(url, options.delete(:host)) + puts "getting #{url} with options: #{options.inspect}" if options[:verbose] - Timeout.timeout(config['timeout']||10) do - open(url, options).read + http_options = {} + http_options[:http_basic_authentication] = options[:http_basic_authentication] if options[:http_basic_authentication] + + res = Timeout.timeout(config['timeout']||10) do + open(url, http_options).read end + puts "result: #{res.inspect}" if options[:verbose] + res rescue Exception => e e.message << url.to_s - unless config['silent_on_errors'] + unless config['silent_on_errors'] raise e + else + puts "caught error: #{e.message} with #{e.backtrace}" end end def self.sheriff_url config['sheriff_url'].sub(%r{/$},'') end def self.config home = File.expand_path('~') - ["#{home}/.deputy.yml", '/etc/deputy.yml'].each do |file| + possible_config_files = ["#{home}/.deputy.yml", '/etc/deputy.yml'] + possible_config_files.each do |file| return YAML.load(File.read(file)) if File.exist?(file) end - raise "No deputy.yml found in /etc or #{home}" + raise "No configuration file found in " + possible_config_files.join('or') + "\nSee http://github.com/dawanda/deputy for more documentation" end def self.minutes_to_wait(start_time, interval) start_minute = start_time / 60 run_every_n_minutes = interval / 60