Class: RailsTransactionalOutbox::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_transactional_outbox/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: 120) ⇒ HealthCheck

Returns a new instance of HealthCheck.



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

def initialize(hostname: ENV.fetch("HOSTNAME", nil), expiry_time_in_seconds: 120)
  @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/rails_transactional_outbox/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/rails_transactional_outbox/health_check.rb', line 13

def hostname
  @hostname
end

Class Method Details

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



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

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

Instance Method Details

#checkObject



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

def check
  if healthcheck_storage.running?
    ""
  else
    "[Rails Transactional Outbox Worker healthcheck failed]"
  end
end

#register_heartbeatObject



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

def register_heartbeat
  healthcheck_storage.touch
end

#worker_stoppedObject



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

def worker_stopped
  healthcheck_storage.remove
end