Class: Wellness::SimpleReport
- Inherits:
-
Object
- Object
- Wellness::SimpleReport
- Defined in:
- lib/wellness/simple_report.rb
Constant Summary collapse
- STATUSES =
{ 'HEALTHY' => 200, 'DEGRADED' => 200, 'UNHEALTHY' => 500 }
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(system) ⇒ SimpleReport
constructor
A new instance of SimpleReport.
-
#render(options = {}) ⇒ Object
Behaves similar to Rail’s controller render method.
Constructor Details
#initialize(system) ⇒ SimpleReport
Returns a new instance of SimpleReport.
11 12 13 |
# File 'lib/wellness/simple_report.rb', line 11 def initialize(system) @system = system end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wellness/simple_report.rb', line 15 def call non_criticals = [] criticals = [] @system.services.each do |name, service| result = service.call['status'] if service.critical? criticals << result else non_criticals << result end end healthy = criticals.all? { |s| s == 'HEALTHY' } degraded = non_criticals.any? { |s| s == 'UNHEALTHY' } if healthy if degraded status = 'DEGRADED' else status = 'HEALTHY' end else status = 'UNHEALTHY' end render({json: { 'status' => status }, status: STATUSES[status]}) end |
#render(options = {}) ⇒ Object
Behaves similar to Rail’s controller render method
46 47 48 49 50 51 |
# File 'lib/wellness/simple_report.rb', line 46 def render(={}) status = [:status] || 200 response = JSON.dump([:json]) [status, { 'Content-Type' => 'application/json' }, [response]] end |