Class: ActiveRecord::ConnectionAdapters::MasterSlaveAdapter::CircuitBreaker
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::MasterSlaveAdapter::CircuitBreaker
- Defined in:
- lib/active_record/connection_adapters/master_slave_adapter/circuit_breaker.rb
Instance Method Summary collapse
- #fail! ⇒ Object
-
#initialize(logger = nil, failure_threshold = 5, timeout = 30) ⇒ CircuitBreaker
constructor
A new instance of CircuitBreaker.
- #success! ⇒ Object
- #tripped? ⇒ Boolean
Constructor Details
#initialize(logger = nil, failure_threshold = 5, timeout = 30) ⇒ CircuitBreaker
Returns a new instance of CircuitBreaker.
5 6 7 8 9 10 11 |
# File 'lib/active_record/connection_adapters/master_slave_adapter/circuit_breaker.rb', line 5 def initialize(logger = nil, failure_threshold = 5, timeout = 30) @logger = logger @failure_count = 0 @failure_threshold = failure_threshold @timeout = timeout @state = :closed end |
Instance Method Details
#fail! ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/active_record/connection_adapters/master_slave_adapter/circuit_breaker.rb', line 28 def fail! @failure_count += 1 if !open? && @failure_count >= @failure_threshold @opened_at = Time.now change_state_to :open end end |
#success! ⇒ Object
21 22 23 24 25 26 |
# File 'lib/active_record/connection_adapters/master_slave_adapter/circuit_breaker.rb', line 21 def success! if !closed? @failure_count = 0 change_state_to :closed end end |
#tripped? ⇒ Boolean
13 14 15 16 17 18 19 |
# File 'lib/active_record/connection_adapters/master_slave_adapter/circuit_breaker.rb', line 13 def tripped? if open? && timeout_exceeded? change_state_to :half_open end open? end |