Class: HTTPX::Plugins::CircuitBreaker::CircuitStore
- Inherits:
-
Object
- Object
- HTTPX::Plugins::CircuitBreaker::CircuitStore
- Defined in:
- lib/httpx/plugins/circuit_breaker/circuit_store.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ CircuitStore
constructor
A new instance of CircuitStore.
- #try_close(uri) ⇒ Object
- #try_open(uri, response) ⇒ Object
-
#try_respond(request) ⇒ Object
if circuit is open, it’ll respond with the stored response.
Constructor Details
#initialize(options) ⇒ CircuitStore
Returns a new instance of CircuitStore.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/httpx/plugins/circuit_breaker/circuit_store.rb', line 7 def initialize() @circuits = Hash.new do |h, k| h[k] = Circuit.new( .circuit_breaker_max_attempts, .circuit_breaker_reset_attempts_in, .circuit_breaker_break_in, .circuit_breaker_half_open_drip_rate ) end @circuits_mutex = Thread::Mutex.new end |
Instance Method Details
#try_close(uri) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/httpx/plugins/circuit_breaker/circuit_store.rb', line 25 def try_close(uri) circuit = @circuits_mutex.synchronize do return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s) get_circuit_for_uri(uri) end circuit.try_close end |
#try_open(uri, response) ⇒ Object
19 20 21 22 23 |
# File 'lib/httpx/plugins/circuit_breaker/circuit_store.rb', line 19 def try_open(uri, response) circuit = @circuits_mutex.synchronize { get_circuit_for_uri(uri) } circuit.try_open(response) end |
#try_respond(request) ⇒ Object
if circuit is open, it’ll respond with the stored response. if not, nil.
37 38 39 40 41 |
# File 'lib/httpx/plugins/circuit_breaker/circuit_store.rb', line 37 def try_respond(request) circuit = @circuits_mutex.synchronize { get_circuit_for_uri(request.uri) } circuit.respond end |