Class: MiddlewareHealthcheck::DefaultCheckers::ActiveRecordChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/middleware_healthcheck/default_checkers/active_record_checker.rb

Constant Summary collapse

NOT_CONNECTED_ERROR =
"Can't connect to database.".freeze
EXCEPTION_REGEXP =
/^ActiveRecord::/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_app, _env) ⇒ ActiveRecordChecker

Returns a new instance of ActiveRecordChecker.



9
10
# File 'lib/middleware_healthcheck/default_checkers/active_record_checker.rb', line 9

def initialize(_app, _env)
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



7
8
9
# File 'lib/middleware_healthcheck/default_checkers/active_record_checker.rb', line 7

def error
  @error
end

Instance Method Details

#healthy?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/middleware_healthcheck/default_checkers/active_record_checker.rb', line 12

def healthy?
  ActiveRecord::Base.establish_connection
  ActiveRecord::Base.connection
  if ActiveRecord::Base.connected?
    true
  else
    self.error = NOT_CONNECTED_ERROR
    false
  end
rescue => e
  if e.class.to_s.match EXCEPTION_REGEXP
    self.error = e.message
    false
  else
    raise e
  end
end