Class: Easymon::SplitActiveRecordCheck
- Inherits:
-
Object
- Object
- Easymon::SplitActiveRecordCheck
- Defined in:
- lib/easymon/checks/split_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
Assumes only 2 connections.
-
#initialize(&block) ⇒ SplitActiveRecordCheck
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) ⇒ SplitActiveRecordCheck
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 Replica < ActiveRecord::Base
establish_connection :"primary_replica"
end
end
We would check both it and ActiveRecord::Base like so: check = Easymon::SplitActiveRecordCheck.new
[ActiveRecord::Base.connection, Easymon::Replica.connection]
Easymon::Repository.add(“split-database”, check)
21 22 23 |
# File 'lib/easymon/checks/split_active_record_check.rb', line 21 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/split_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/split_active_record_check.rb', line 4 def results @results end |
Instance Method Details
#check ⇒ Object
Assumes only 2 connections
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/easymon/checks/split_active_record_check.rb', line 26 def check connections = Array(@block.call) results = connections.map { |connection| database_up?(connection) } primary_status = results.first ? "Primary: Up" : "Primary: Down" replica_status = results.last ? "Replica: Up" : "Replica: Down" [ (results.all? && results.count > 0), "#{primary_status} - #{replica_status}" ] end |