Class: EventMachine::CircuitBreaker::Breaker

Inherits:
Object
  • Object
show all
Defined in:
lib/eventmachine/circuit_breaker/breaker.rb

Instance Method Summary collapse

Constructor Details

#initialize(strategy = Strategy::Basic.new) ⇒ Breaker

Returns a new instance of Breaker.



4
5
6
# File 'lib/eventmachine/circuit_breaker/breaker.rb', line 4

def initialize(strategy = Strategy::Basic.new)
  @strategy = strategy
end

Instance Method Details

#request(client, headers, body) ⇒ Object



8
9
10
11
# File 'lib/eventmachine/circuit_breaker/breaker.rb', line 8

def request(client, headers, body)
  close!(client) if strategy.open?
  [headers, body]
end

#response(client) ⇒ Object



13
14
15
16
# File 'lib/eventmachine/circuit_breaker/breaker.rb', line 13

def response(client)
  strategy.handle_response(client)
  close!(client) if strategy.open?
end