Class: Dionysus::Checks::HealthCheck

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname: ENV.fetch("HOSTNAME", nil), expiry_time_in_seconds: ENV.fetch(KARAFKA_TIMEOUT, 600)) ⇒ HealthCheck

Returns a new instance of HealthCheck.



15
16
17
18
# File 'lib/dionysus/checks/health_check.rb', line 15

def initialize(hostname: ENV.fetch("HOSTNAME", nil), expiry_time_in_seconds: ENV.fetch(KARAFKA_TIMEOUT, 600))
  @hostname = hostname
  @expiry_time_in_seconds = expiry_time_in_seconds
end

Instance Attribute Details

#expiry_time_in_secondsObject (readonly)

Returns the value of attribute expiry_time_in_seconds.



13
14
15
# File 'lib/dionysus/checks/health_check.rb', line 13

def expiry_time_in_seconds
  @expiry_time_in_seconds
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



13
14
15
# File 'lib/dionysus/checks/health_check.rb', line 13

def hostname
  @hostname
end

Class Method Details

.check(hostname: ENV.fetch("HOSTNAME", nil), expiry_time_in_seconds: ENV.fetch(KARAFKA_TIMEOUT, 600)) ⇒ Object



9
10
11
# File 'lib/dionysus/checks/health_check.rb', line 9

def self.check(hostname: ENV.fetch("HOSTNAME", nil), expiry_time_in_seconds: ENV.fetch(KARAFKA_TIMEOUT, 600))
  new(hostname: hostname, expiry_time_in_seconds: expiry_time_in_seconds).check
end

Instance Method Details

#app_initialized!Object



28
29
30
# File 'lib/dionysus/checks/health_check.rb', line 28

def app_initialized!
  register_heartbeat
end

#app_stopped!Object



36
37
38
# File 'lib/dionysus/checks/health_check.rb', line 36

def app_stopped!
  healthcheck_storage.remove
end

#checkObject



20
21
22
23
24
25
26
# File 'lib/dionysus/checks/health_check.rb', line 20

def check
  if healthcheck_storage.running?
    ""
  else
    "[Dionysus healthcheck failed]"
  end
end

#register_heartbeatObject



32
33
34
# File 'lib/dionysus/checks/health_check.rb', line 32

def register_heartbeat
  healthcheck_storage.touch
end