Module: Tina4::Health

Defined in:
lib/tina4/health.rb

Constant Summary collapse

START_TIME =
Process.clock_gettime(Process::CLOCK_MONOTONIC)

Class Method Summary collapse

Class Method Details

.handle(_request, response) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tina4/health.rb', line 25

def handle(_request, response)
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  uptime = (now - START_TIME).round(2)

  payload = {
    status: "ok",
    version: Tina4::VERSION,
    uptime: uptime,
    framework: "tina4-ruby"
  }

  response.json(payload)
end

.pathObject

Return the configured health endpoint path. TINA4_HEALTH_PATH overrides the default “/__health” — kept consistent across all 4 frameworks.



12
13
14
15
16
# File 'lib/tina4/health.rb', line 12

def path
  configured = ENV["TINA4_HEALTH_PATH"]
  return "/__health" if configured.nil? || configured.empty?
  configured.start_with?("/") ? configured : "/#{configured}"
end

.register!Object



18
19
20
21
22
23
# File 'lib/tina4/health.rb', line 18

def register!
  # Register at the configured path. The legacy "/health" path stays
  # registered for backward-compat.
  Tina4::Router.add("GET", path, method(:handle))
  Tina4::Router.add("GET", "/health", method(:handle)) unless path == "/health"
end

.statusObject



39
40
41
42
43
44
45
46
47
# File 'lib/tina4/health.rb', line 39

def status
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  {
    status: "ok",
    version: Tina4::VERSION,
    uptime: (now - START_TIME).round(2),
    framework: "tina4-ruby"
  }
end