Class: Nugget::Backstop

Inherits:
Object
  • Object
show all
Defined in:
lib/nugget/backstop.rb

Class Method Summary collapse

Class Method Details

.backstop_requst(metric, value) ⇒ Object



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
# File 'lib/nugget/backstop.rb', line 27

def self.backstop_requst(metric, value)

  Nugget::Log.debug("Sending the following to backstop: #{metric}: #{value}")

  body = [{
    :metric => metric,
    :value => value,
    :measure_time => Time.now.to_i
  }].to_json

  request = Typhoeus::Request.new(
    Nugget::Config.backstop_url,
    :method => :post,
    :body => body,
    :headers => { 'Content-Type' => 'application/json' }
  )

  response = request.run

  if response.options[:response_code] > 299
    # hack a bad response error in here
    Nugget::Log.error("Error publishing #{metric} to backstop, got #{response.options[:response_code]}")
  end

end

.send_metrics(name, result, response) ⇒ Object



4
5
6
7
# File 'lib/nugget/backstop.rb', line 4

def self.send_metrics(name, result, response)
  send_test_result(name, result)
  send_test_timings(name, response)
end

.send_test_result(name, result) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/nugget/backstop.rb', line 9

def self.send_test_result(name, result)

  if result == "FAIL"
    backstop_requst("#{name}.result", 1)
  end

end

.send_test_timings(name, response) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/nugget/backstop.rb', line 17

def self.send_test_timings(name, response)

  response.each do |key, value|
    if key.to_s.include?("_time")
      backstop_requst("#{name}.#{key}", value)
    end
  end

end