Class: Protoboard::Helpers::ServicesHealthcheckGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/protoboard/helpers/services_healthcheck_generator.rb

Overview

This class is responsible to generate information about the circuits added

Instance Method Summary collapse

Instance Method Details

#call(with_namespace:) ⇒ Object

Verifies the list of circuits added and returns a hash with the circuits names and its states.

 ==== Examples
{
  'services' => {
    'my_service_name' => {
      'circuits' => {
        'some_namespace/my_service_name/SomeClass#some_method' => 'OK',
        'my_custom_name' => 'NOT_OK'
      }
    }
  }
}
====


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/protoboard/helpers/services_healthcheck_generator.rb', line 25

def call(with_namespace:)
  circuits_hash = Protoboard::CircuitBreaker.registered_circuits.map do |circuit|
    state = Protoboard.config.adapter.check_state(circuit.name)

    { name: circuit.name, status: state, service: circuit.service }
  end
  services_hash = circuits_hash
                  .group_by { |circuit| circuit[:service] }
                  .map do |service, circuits_hash|

    circuits = circuits_hash.each_with_object({}) do |circuit, memo|
      circuit_name = format_circuit_name(circuit[:name], with_namespace: with_namespace)
      memo[circuit_name] = circuit[:status]
    end
    { service => { 'circuits' => circuits } }
  end.reduce(:merge)

  { 'services' => services_hash.to_h }
end