debian-mirror-gitlab/lib/gitlab/health_checks/base_abstract_check.rb

46 lines
777 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module HealthChecks
module BaseAbstractCheck
def name
super.demodulize.underscore
end
def human_name
name.sub(/_check$/, '').capitalize
end
2021-03-11 19:13:27 +05:30
def available?
true
end
2017-08-17 22:00:37 +05:30
def readiness
raise NotImplementedError
end
def metrics
[]
end
protected
def metric(name, value, **labels)
Metric.new(name, value, labels)
end
2017-09-10 17:25:29 +05:30
def with_timing
2017-08-17 22:00:37 +05:30
start = Time.now
2017-09-10 17:25:29 +05:30
result = yield
[result, Time.now.to_f - start.to_f]
2017-08-17 22:00:37 +05:30
end
def catch_timeout(seconds, &block)
2020-03-13 15:44:24 +05:30
Timeout.timeout(seconds.to_i, &block)
rescue Timeout::Error => ex
ex
2017-08-17 22:00:37 +05:30
end
end
end
end