Class: Rack::Healthz
- Inherits:
-
Object
show all
- Defined in:
- lib/rack/healthz.rb,
lib/rack/healthz/version.rb,
lib/rack/healthz/response.rb,
lib/rack/healthz/accumulator.rb,
lib/rack/healthz/request_accumulator.rb
Defined Under Namespace
Classes: Accumulator, Error, RequestAccumulator, Response
Constant Summary
collapse
- DefaultPath =
'/healthz'
- DefaultTimeBetweenRequests =
3600
- HealthyStatus =
200
- UnhealthyStatus =
503
- ContentType =
{'Content-Type' => 'application/json'}
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(app, **args) ⇒ Healthz
Returns a new instance of Healthz.
39
40
41
|
# File 'lib/rack/healthz.rb', line 39
def initialize(app, **args)
@accumulator = Accumulator.new(app, **args)
end
|
Instance Attribute Details
#accumulator ⇒ Object
Returns the value of attribute accumulator.
37
38
39
|
# File 'lib/rack/healthz.rb', line 37
def accumulator
@accumulator
end
|
Class Method Details
.current_time ⇒ Object
21
22
23
|
# File 'lib/rack/healthz.rb', line 21
def current_time
Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
|
.measure(&block) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/rack/healthz.rb', line 25
def measure(&block)
start_time = current_time
block.call
current_time - start_time
end
|
Instance Method Details
#call(env) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/rack/healthz.rb', line 43
def call(env)
with_now do
if accumulator.status_request?(env)
accumulator.response.to_a
else
accumulator.call(env).to_a
end
end
end
|
#with_now ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/rack/healthz.rb', line 53
def with_now
old_now = Thread.current[:now]
Thread.current[:now] = Healthz.current_time
result = yield
Thread.current[:now] = old_now
result
end
|