Module: HTTPX::Plugins::CircuitBreaker::OptionsMethods
- Defined in:
- lib/httpx/plugins/circuit_breaker.rb
Overview
adds support for the following options:
:circuit_breaker_max_attempts :: the number of attempts the circuit allows, before it is opened (defaults to 3). :circuit_breaker_reset_attempts_in :: the time a circuit stays open at most, before it resets (defaults to 60). :circuit_breaker_break_on :: callable defining an alternative rule for a response to break (i.e. ->(res) { res.status == 429 } ) :circuit_breaker_break_in :: the time that must elapse before an open circuit can transit to the half-open state (defaults to <60). :circuit_breaker_half_open_drip_rate :: the rate of requests a circuit allows to be performed when in an half-open state (defaults to 1).
Instance Method Summary collapse
- #option_circuit_breaker_break_in(value) ⇒ Object
- #option_circuit_breaker_break_on(value) ⇒ Object
- #option_circuit_breaker_half_open_drip_rate(value) ⇒ Object
- #option_circuit_breaker_max_attempts(value) ⇒ Object
- #option_circuit_breaker_reset_attempts_in(value) ⇒ Object
Instance Method Details
#option_circuit_breaker_break_in(value) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/httpx/plugins/circuit_breaker.rb', line 121 def option_circuit_breaker_break_in(value) timeout = Float(value) raise TypeError, ":circuit_breaker_break_in must be positive" unless timeout.positive? timeout end |
#option_circuit_breaker_break_on(value) ⇒ Object
135 136 137 138 139 |
# File 'lib/httpx/plugins/circuit_breaker.rb', line 135 def option_circuit_breaker_break_on(value) raise TypeError, ":circuit_breaker_break_on must be called with the response" unless value.respond_to?(:call) value end |
#option_circuit_breaker_half_open_drip_rate(value) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/httpx/plugins/circuit_breaker.rb', line 128 def option_circuit_breaker_half_open_drip_rate(value) ratio = Float(value) raise TypeError, ":circuit_breaker_half_open_drip_rate must be a number between 0 and 1" unless (0..1).cover?(ratio) ratio end |
#option_circuit_breaker_max_attempts(value) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/httpx/plugins/circuit_breaker.rb', line 107 def option_circuit_breaker_max_attempts(value) attempts = Integer(value) raise TypeError, ":circuit_breaker_max_attempts must be positive" unless attempts.positive? attempts end |
#option_circuit_breaker_reset_attempts_in(value) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/httpx/plugins/circuit_breaker.rb', line 114 def option_circuit_breaker_reset_attempts_in(value) timeout = Float(value) raise TypeError, ":circuit_breaker_reset_attempts_in must be positive" unless timeout.positive? timeout end |