Module: BreakerMachines::Circuit::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- BreakerMachines::Circuit
- Defined in:
- lib/breaker_machines/circuit/base.rb
Overview
Base provides the common initialization and setup logic shared by all circuit types
Instance Method Summary collapse
Instance Method Details
#initialize(name, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/breaker_machines/circuit/base.rb', line 25 def initialize(name, = {}) @name = name @config = default_config.merge() # Always use a storage backend for proper sliding window implementation # Use global default storage if not specified @storage = @config[:storage] || create_default_storage @metrics = @config[:metrics] @opened_at = Concurrent::AtomicReference.new(nil) @half_open_attempts = Concurrent::AtomicFixnum.new(0) @half_open_successes = Concurrent::AtomicFixnum.new(0) @mutex = Concurrent::ReentrantReadWriteLock.new @last_failure_at = Concurrent::AtomicReference.new(nil) @last_error = Concurrent::AtomicReference.new(nil) # Initialize semaphore for bulkheading if max_concurrent is set @semaphore = (Concurrent::Semaphore.new(@config[:max_concurrent]) if @config[:max_concurrent]) restore_status_from_storage if @storage # Register with global registry unless auto_register is disabled BreakerMachines::Registry.instance.register(self) unless @config[:auto_register] == false end |