Class: RailsHealthChecks::CheckRegistry
- Inherits:
-
Object
- Object
- RailsHealthChecks::CheckRegistry
- Defined in:
- lib/rails_health_checks/check_registry.rb
Constant Summary collapse
- BUILT_INS =
{ database: -> { Checks::DatabaseCheck.new }, cache: -> { Checks::CacheCheck.new }, sidekiq: -> { Checks::SidekiqCheck.new(queue_size: RailsHealthChecks.configuration.sidekiq_queue_size) }, solid_queue: -> { Checks::SolidQueueCheck.new(job_count: RailsHealthChecks.configuration.solid_queue_job_count) }, good_job: -> { Checks::GoodJobCheck.new(latency: RailsHealthChecks.configuration.good_job_latency) }, resque: -> { Checks::ResqueCheck.new(queue_size: RailsHealthChecks.configuration.resque_queue_size) }, memory: -> { Checks::MemoryCheck.new(threshold: RailsHealthChecks.configuration.memory_threshold) }, http: -> { Checks::HttpCheck.new( url: RailsHealthChecks.configuration.http_url, expected_status: RailsHealthChecks.configuration.http_expected_status, headers: RailsHealthChecks.configuration.http_headers ) }, disk: -> { Checks::DiskCheck.new( warn_threshold: RailsHealthChecks.configuration.disk_warn_threshold, critical_threshold: RailsHealthChecks.configuration.disk_critical_threshold, path: RailsHealthChecks.configuration.disk_path ) } }.freeze
Class Method Summary collapse
Class Method Details
.build(check_names) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rails_health_checks/check_registry.rb', line 28 def self.build(check_names) custom = RailsHealthChecks.configuration.custom_checks check_names.each_with_object({}) do |name, hash| if BUILT_INS.key?(name) hash[name] = BUILT_INS[name].call elsif custom.key?(name) hash[name] = custom[name].dup else available = (BUILT_INS.keys + custom.keys).join(", ") raise ArgumentError, "Unknown check: #{name}. Available: #{available}" end end end |
.run(checks, timeout:) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_health_checks/check_registry.rb', line 42 def self.run(checks, timeout:) results = {} ActiveSupport::Notifications.instrument("health_check.rails_health_checks") do |payload| futures = checks.transform_values do |check| t = check.timeout || timeout Concurrent::Future.execute { run_check(check, timeout: t) } end checks.each do |name, check| t = check.timeout || timeout results[name] = futures[name].value(t + 1) || mark_critical(check, "timed out") end payload[:status] = overall_status(results) payload[:checks] = results.transform_values do |c| { status: c.status, message: c., latency_ms: c.latency_ms }.compact end end results end |