Class: Leafy::Health::HealthCheck

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ HealthCheck

Returns a new instance of HealthCheck.



36
37
38
# File 'lib/leafy/health/health_check.rb', line 36

def initialize( &block )
  @block = block if block
end

Instance Method Details

#callObject



77
78
79
80
81
82
83
# File 'lib/leafy/health/health_check.rb', line 77

def call
  if @block
    instance_eval( &@block )
  else
    'health check "call" method not implemented'
  end
end

#checkObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/leafy/health/health_check.rb', line 64

def check
  case result = call
  when String
    unhealthy( result )
  when NilClass
    healthy
  when com.codahale.metrics.health.HealthCheck::Result
    result
  else
    raise 'wrong result type'
  end
end

#healthy(result = nil) ⇒ Object

create healthy result object with given message

param [String] optional result message, can be nil return [com.codahale.metrics.health.HealthCheck::Result]



44
45
46
47
48
49
50
# File 'lib/leafy/health/health_check.rb', line 44

def healthy( result = nil )
  if result.is_a? Hash
    com.codahale.metrics.health.HealthCheck::Result.healthy( result.to_json )
  else
    com.codahale.metrics.health.HealthCheck::Result.healthy( result )
  end
end

#unhealthy(result) ⇒ Object

create unhealthy result object with given message

param [String] result message return [com.codahale.metrics.health.HealthCheck::Result]



56
57
58
59
60
61
62
# File 'lib/leafy/health/health_check.rb', line 56

def unhealthy( result )
  if result.is_a? Hash
    com.codahale.metrics.health.HealthCheck::Result.unhealthy( result.to_json )
  else
    com.codahale.metrics.health.HealthCheck::Result.unhealthy( result )
  end
end