summaryrefslogtreecommitdiff
path: root/lib/gitlab/health_checks/db_check.rb
blob: ec4b97eaca4aaf9d9e1847c449adc7f61811996e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Gitlab
  module HealthChecks
    class DbCheck
      extend SimpleAbstractCheck

      class << self
        private

        def metric_prefix
          'db_ping'
        end

        def successful?(result)
          result == '1'
        end

        def check
          catch_timeout 10.seconds do
            ActiveRecord::Base.connection.execute('SELECT 1 as ping')&.first&.[]('ping')&.to_s
          end
        end
      end
    end
  end
end