Module: Protoboard::CircuitBreaker
- Defined in:
- lib/protoboard/circuit_breaker.rb
Overview
This module is responsible to manage the circuits.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.add_circuit(circuit) ⇒ Object
Adds a
circuit
to the list of registeredcircuits
. -
.circuits ⇒ Object
Returns a list of
circuits
. -
.create_circuit_proxy(circuits, class_name) ⇒ Object
Calls the module responsible for creating the proxy module that will execute the circuit.
-
.create_circuits(circuit_methods, class_name, options, singleton_methods) ⇒ Object
Creates a new
circuit
. - .included(klass) ⇒ Object
-
.registered_circuits ⇒ Object
Returns a list of registered
circuits
. -
.services_healthcheck(with_namespace: true) ⇒ Object
Returns a hash with the
circuits
names and its states.
Class Method Details
.add_circuit(circuit) ⇒ Object
Adds a circuit
to the list of registered circuits
.
73 74 75 |
# File 'lib/protoboard/circuit_breaker.rb', line 73 def add_circuit(circuit) circuits << circuit end |
.circuits ⇒ Object
Returns a list of circuits
.
79 80 81 |
# File 'lib/protoboard/circuit_breaker.rb', line 79 def circuits @circuits ||= [] end |
.create_circuit_proxy(circuits, class_name) ⇒ Object
Calls the module responsible for creating the proxy module that will execute the circuit.
85 86 87 |
# File 'lib/protoboard/circuit_breaker.rb', line 85 def create_circuit_proxy(circuits, class_name) CircuitProxyFactory.create_module(circuits, class_name) end |
.create_circuits(circuit_methods, class_name, options, singleton_methods) ⇒ Object
Creates a new circuit
.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/protoboard/circuit_breaker.rb', line 91 def create_circuits(circuit_methods,class_name, , singleton_methods) circuit_hash = case circuit_methods when Array circuit_methods.reduce({}) do |memo, value| memo.merge(value.to_sym => "#{formatted_namespace}#{[:service]}/#{class_name}\##{value}") end when Hash circuit_methods.map { |key, value| [key, "#{formatted_namespace}#{value}"] }.to_h else raise ArgumentError, 'Invalid input for circuit methods' end circuit_hash.map do |circuit_method, circuit_name| Circuit.new({ name: circuit_name, method_name: circuit_method, singleton_method: singleton_methods.include?(circuit_method.to_sym) } .merge()) end end |
.included(klass) ⇒ Object
113 114 115 |
# File 'lib/protoboard/circuit_breaker.rb', line 113 def included(klass) klass.extend(ClassMethods) end |
.registered_circuits ⇒ Object
Returns a list of registered circuits
.
67 68 69 |
# File 'lib/protoboard/circuit_breaker.rb', line 67 def registered_circuits circuits end |
.services_healthcheck(with_namespace: true) ⇒ Object
Returns a hash with the circuits
names and its states.
61 62 63 |
# File 'lib/protoboard/circuit_breaker.rb', line 61 def services_healthcheck(with_namespace: true) Protoboard::Helpers::ServicesHealthcheckGenerator.new.call(with_namespace: with_namespace) end |