Class: HealthRails::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/health_rails/health_check.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.check(description, auto_activated, &block) ⇒ Object



41
42
43
44
45
46
# File 'lib/health_rails/health_check.rb', line 41

def check(description, auto_activated, &block)
  if auto_activated && !HealthRails.health_checks.include?(description)
    HealthRails.health_checks << description
  end
  checks[description] = block
end

.checksObject



48
49
50
# File 'lib/health_rails/health_check.rb', line 48

def checks
  @@checks ||= {}
end

Instance Method Details

#all_ok?Boolean

Returns:

  • (Boolean)


3
4
5
6
# File 'lib/health_rails/health_check.rb', line 3

def all_ok?
  process_checks
  !errors.any?
end

#check(description) ⇒ Object



8
9
10
# File 'lib/health_rails/health_check.rb', line 8

def check(description)
  checks[description]
end

#checksObject



12
13
14
# File 'lib/health_rails/health_check.rb', line 12

def checks
  HealthCheck.checks
end

#error_messagesObject



16
17
18
# File 'lib/health_rails/health_check.rb', line 16

def error_messages
  errors.join("\n")
end

#errorsObject



20
21
22
# File 'lib/health_rails/health_check.rb', line 20

def errors
  @errors ||= []
end

#process_check(description) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/health_rails/health_check.rb', line 24

def process_check(description)
  begin
    check(description).call
  rescue HealthCheckFailure => error_message
    errors << "#{description}: #{error_message}"
  end
end

#process_checksObject



32
33
34
35
36
37
# File 'lib/health_rails/health_check.rb', line 32

def process_checks
  checks.each do |description, proc|
    next unless HealthRails.health_checks.include?(description)
    process_check(description)
  end
end