Class: Easymon::MultiActiveRecordCheck
- Inherits:
-
Object
- Object
- Easymon::MultiActiveRecordCheck
- Defined in:
- lib/easymon/checks/multi_active_record_check.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(&block) ⇒ MultiActiveRecordCheck
constructor
Here we pass a block so we get a fresh instance of ActiveRecord::Base or whatever other class we might be using to make database connections.
Constructor Details
#initialize(&block) ⇒ MultiActiveRecordCheck
Here we pass a block so we get a fresh instance of ActiveRecord::Base or whatever other class we might be using to make database connections
For example, given the following other class: module Easymon
class PrimaryReplica < ActiveRecord::Base
establish_connection :"primary_replica"
end
class OtherReplica < ActiveRecord::Base
establish_connection :"other_replica"
end
end
We would check both it and ActiveRecord::Base like so: check = Easymon::MultiActiveRecordCheck.new {
{
"Primary": ActiveRecord::Base.connection,
"PrimaryReplica": Easymon::PrimaryReplica.connection
"OtherReplica": Easymon::OtherReplica.connection
}
} Easymon::Repository.add(“multi-database”, check)
30 31 32 |
# File 'lib/easymon/checks/multi_active_record_check.rb', line 30 def initialize(&block) self.block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/easymon/checks/multi_active_record_check.rb', line 3 def block @block end |
#results ⇒ Object
Returns the value of attribute results.
4 5 6 |
# File 'lib/easymon/checks/multi_active_record_check.rb', line 4 def results @results end |
Instance Method Details
#check ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/easymon/checks/multi_active_record_check.rb', line 34 def check connections = Hash(@block.call) results = connections.transform_values { |connection| database_up?(connection) } status = results.map { |db_name, result| "#{db_name}: #{result ? 'Up' : 'Down'}" }.join(" - ") [ (results.any? && results.values.all?), status ] end |