Sha256: 50ba601cf41e5753d713c09f13688bd3849183245ffc4da05801fcac1a350f82
Contents?: true
Size: 1.14 KB
Versions: 2
Compression:
Stored size: 1.14 KB
Contents
require 'aasm' # # CircuitState is created individually for each object, and keeps # track of how the object is doing and whether the object's circuit # has tripped or not. # class CircuitBreaker::CircuitState include AASM aasm.state :half_open aasm.state :open aasm.state :closed, :enter => :reset_failure_count aasm.initial_state :closed # # Trips the circuit breaker into the open state where it will immediately fail. # aasm.event :trip do transitions :to => :open, :from => [:closed, :half_open] end # # Transitions from an open state to a half_open state. # aasm.event :attempt_reset do transitions :to => :half_open, :from => [:open] end # # Close the circuit from an open or half open state. # aasm.event :reset do transitions :to => :closed, :from => [:open, :half_open] end def initialize() @failure_count = 0 @last_failure_time = nil end attr_accessor :last_failure_time attr_accessor :failure_count def increment_failure_count @failure_count = @failure_count + 1 @last_failure_time = Time.now end def reset_failure_count @failure_count = 0 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
circuit_breaker-1.1.2 | lib/circuit_breaker/circuit_state.rb |
circuit_breaker-1.1.1 | lib/circuit_breaker/circuit_state.rb |