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



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tina4/health.rb', line 14

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

.register!Object



10
11
12
# File 'lib/tina4/health.rb', line 10

def register!
  Tina4::Router.add("GET", "/health", method(:handle))
end

.statusObject



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

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