class HTTPX::Plugins::CircuitBreaker::CircuitStore

  1. lib/httpx/plugins/circuit_breaker/circuit_store.rb
Superclass: Object

Methods

Public Class

  1. new

Public Instance

  1. try_close
  2. try_open
  3. try_respond

Public Class methods

new(options)
[show source]
   # File lib/httpx/plugins/circuit_breaker/circuit_store.rb
 7 def initialize(options)
 8   @circuits = Hash.new do |h, k|
 9     h[k] = Circuit.new(
10       options.circuit_breaker_max_attempts,
11       options.circuit_breaker_reset_attempts_in,
12       options.circuit_breaker_break_in,
13       options.circuit_breaker_half_open_drip_rate
14     )
15   end
16   @circuits_mutex = Thread::Mutex.new
17 end

Public Instance methods

try_close(uri)
[show source]
   # File lib/httpx/plugins/circuit_breaker/circuit_store.rb
25 def try_close(uri)
26   circuit = @circuits_mutex.synchronize do
27     return unless @circuits.key?(uri.origin) || @circuits.key?(uri.to_s)
28 
29     get_circuit_for_uri(uri)
30   end
31 
32   circuit.try_close
33 end
try_open(uri, response)
[show source]
   # File lib/httpx/plugins/circuit_breaker/circuit_store.rb
19 def try_open(uri, response)
20   circuit = @circuits_mutex.synchronize { get_circuit_for_uri(uri) }
21 
22   circuit.try_open(response)
23 end
try_respond(request)

if circuit is open, it’ll respond with the stored response. if not, nil.

[show source]
   # File lib/httpx/plugins/circuit_breaker/circuit_store.rb
37 def try_respond(request)
38   circuit = @circuits_mutex.synchronize { get_circuit_for_uri(request.uri) }
39 
40   circuit.respond
41 end