Class: OkComputer::RabbitmqCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/ok_computer/built_in_checks/rabbitmq_check.rb

Constant Summary collapse

ConnectionFailed =
Class.new(StandardError)

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(url = nil) ⇒ RabbitmqCheck

Returns a new instance of RabbitmqCheck.



5
6
7
# File 'lib/ok_computer/built_in_checks/rabbitmq_check.rb', line 5

def initialize(url = nil)
  @url = url || ENV['CLOUDAMQP_URL'] || ENV['AMQP_HOST']
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/ok_computer/built_in_checks/rabbitmq_check.rb', line 3

def url
  @url
end

Instance Method Details

#checkObject



9
10
11
12
13
14
15
# File 'lib/ok_computer/built_in_checks/rabbitmq_check.rb', line 9

def check
  mark_message "Connected Successfully"
  mark_message "Rabbit Connection Status: (#{connection_status})"
rescue => e
  mark_failure
  mark_message "Error: '#{e}'"
end

#connection_statusObject



17
18
19
20
21
22
23
24
25
# File 'lib/ok_computer/built_in_checks/rabbitmq_check.rb', line 17

def connection_status
  connection = Bunny.new(@url)
  connection.start
  status = connection.status
  connection.close
  status
rescue => e
  raise ConnectionFailed, e
end