module HTTPX module Plugins module CircuitBreaker class CircuitStore @circuits: Hash[String, Circuit] @circuits_mutex: Thread::Mutex def try_open: (uri uri, response response) -> response? def try_respond: (Request request) -> response? def try_close: (http_uri uri) -> void private def get_circuit_for_uri: (uri uri) -> Circuit def initialize: (Options & _CircuitOptions options) -> void end class Circuit @state: :closed | :open | :half_open @max_attempts: Integer @reset_attempts_in: Float @break_in: Float @circuit_breaker_half_open_drip_rate: Float @attempts: Integer @real_attempts: Integer @drip_factor: Integer @response: response? @opened_at: Float? @attempted_at: Float? def respond: () -> response? def try_open: (response) -> response? def try_close: () -> void private def initialize: (Integer max_attempts, Float reset_attempts_in, Float break_in, Float circuit_breaker_half_open_drip_rate) -> void end interface _CircuitOptions def circuit_breaker_max_attempts: () -> Integer def circuit_breaker_reset_attempts_in: () -> Float def circuit_breaker_break_in: () -> Float def circuit_breaker_half_open_drip_rate: () -> Float def circuit_breaker_break_on: () -> (^(Response) -> boolish | nil) end def self.load_dependencies: (singleton(Session)) -> void def self.extra_options: (Options) -> (Options & _CircuitOptions) module InstanceMethods @circuit_store: CircuitStore private def try_circuit_open: (Request request, response response) -> response? end end type sessionCircuitBreaker = Session & CircuitBreaker::InstanceMethods end end