module HTTPX::Plugins::CircuitBreaker::OptionsMethods

  1. lib/httpx/plugins/circuit_breaker.rb

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).

Public Instance methods

option_circuit_breaker_break_in(value)
[show source]
    # File lib/httpx/plugins/circuit_breaker.rb
122 def option_circuit_breaker_break_in(value)
123   timeout = Float(value)
124   raise TypeError, ":circuit_breaker_break_in must be positive" unless timeout.positive?
125 
126   timeout
127 end
option_circuit_breaker_break_on(value)
[show source]
    # File lib/httpx/plugins/circuit_breaker.rb
136 def option_circuit_breaker_break_on(value)
137   raise TypeError, ":circuit_breaker_break_on must be called with the response" unless value.respond_to?(:call)
138 
139   value
140 end
option_circuit_breaker_half_open_drip_rate(value)
[show source]
    # File lib/httpx/plugins/circuit_breaker.rb
129 def option_circuit_breaker_half_open_drip_rate(value)
130   ratio = Float(value)
131   raise TypeError, ":circuit_breaker_half_open_drip_rate must be a number between 0 and 1" unless (0..1).cover?(ratio)
132 
133   ratio
134 end
option_circuit_breaker_max_attempts(value)
[show source]
    # File lib/httpx/plugins/circuit_breaker.rb
108 def option_circuit_breaker_max_attempts(value)
109   attempts = Integer(value)
110   raise TypeError, ":circuit_breaker_max_attempts must be positive" unless attempts.positive?
111 
112   attempts
113 end
option_circuit_breaker_reset_attempts_in(value)
[show source]
    # File lib/httpx/plugins/circuit_breaker.rb
115 def option_circuit_breaker_reset_attempts_in(value)
116   timeout = Float(value)
117   raise TypeError, ":circuit_breaker_reset_attempts_in must be positive" unless timeout.positive?
118 
119   timeout
120 end