Class: Rack::ECG::Check::ActiveRecordConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ecg/check/active_record_connection.rb

Instance Method Summary collapse

Constructor Details

#initializeObject

Checks whether ActiveRecord is currently connected to the default database.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rack/ecg/check/active_record_connection.rb', line 9

class ActiveRecordConnection
  def result
    value = ""
    status = Status::OK
    begin
      if defined?(ActiveRecord)
        value = ::ActiveRecord::Base.connection.active?
        status = value ? Status::OK : Status::ERROR
      else
        status = Status::ERROR
        value = "ActiveRecord not found"
      end
    rescue => e
      status = Status::ERROR
      value = e.message
    end

    Result.new(:active_record, status, value.to_s)
  end

  CheckRegistry.instance.register(:active_record, ActiveRecordConnection)
end

Instance Method Details

#resultObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack/ecg/check/active_record_connection.rb', line 10

def result
  value = ""
  status = Status::OK
  begin
    if defined?(ActiveRecord)
      value = ::ActiveRecord::Base.connection.active?
      status = value ? Status::OK : Status::ERROR
    else
      status = Status::ERROR
      value = "ActiveRecord not found"
    end
  rescue => e
    status = Status::ERROR
    value = e.message
  end

  Result.new(:active_record, status, value.to_s)
end