Sha256: 3968dd8644b75585bdc8d852f332786ddd13793bee93cb76edcf6c5c6d85fc88

Contents?: true

Size: 701 Bytes

Versions: 2

Compression:

Stored size: 701 Bytes

Contents

module MiddlewareHealthcheck
  module DefaultCheckers
    class ActiveRecordChecker
      NOT_CONNECTED_ERROR = "Can't connect to database.".freeze
      EXCEPTION_REGEXP = /^ActiveRecord::/.freeze

      attr_accessor :error

      def initialize(_app, _env)
      end

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleware_healthcheck-0.2.2 lib/middleware_healthcheck/default_checkers/active_record_checker.rb
middleware_healthcheck-0.2.1 lib/middleware_healthcheck/default_checkers/active_record_checker.rb