Class: Nugget::Service
- Inherits:
-
Object
- Object
- Nugget::Service
- Defined in:
- lib/nugget/service.rb
Class Method Summary collapse
- .config_converter(definition) ⇒ Object
- .run ⇒ Object
- .run_daemon ⇒ Object
- .run_once ⇒ Object
- .write_results(results) ⇒ Object
Class Method Details
.config_converter(definition) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/nugget/service.rb', line 64 def self.config_converter(definition) = definition[:request] if [:method] sym_method = [:method].to_sym .store(:method, sym_method) end if [:url] url = [:url] .delete(:url) end { :url => url, :type => definition[:type], :options => } end |
.run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/nugget/service.rb', line 20 def self.run() config_file = File.new(Nugget::Config.config, 'r') parser = Yajl::Parser.new(:symbolize_keys => true) config = parser.parse(config_file) results = Hash.new config.each do |test, definition| result = nil response = nil begin request_definition = config_converter(definition) response_definition = definition[:response] response = Turd.run(request_definition, response_definition) result = "PASS" rescue Exception => e Nugget::Log.error("#{definition[:type]} test #{test} failed!") Nugget::Log.error(e) result = "FAIL" response = e.response end Nugget::Log.info("Test #{test} complete with status #{result}") results.store(test, { :config => definition, :result => result, :response => response, :timestamp => Time.now.to_i }) if Nugget::Config.backstop_url Nugget::Backstop.send_metrics(test, result, response) end end if Nugget::Config.daemon Nugget::Service.write_results(results) end end |
.run_daemon ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/nugget/service.rb', line 4 def self.run_daemon() Nugget::Log.info("Starting up Nugget in daemon mode ...") loop do run() # chill sleep(Nugget::Config.interval.to_i) end end |
.run_once ⇒ Object
15 16 17 18 |
# File 'lib/nugget/service.rb', line 15 def self.run_once() Nugget::Log.info("Starting up Nugget in run-once mode ...") run() end |
.write_results(results) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nugget/service.rb', line 84 def self.write_results(results) begin file = File.open(Nugget::Config.resultsfile, "w") file.puts(results.to_json) file.close rescue Exception => e Nugget::Log.error("Something went wrong with writing out the results file!") Nugget::Log.error(e) end end |