Module: Rcb

Extended by:
ClassMethods
Defined in:
lib/rcb.rb,
lib/rcb/error.rb,
lib/rcb/result.rb,
lib/rcb/instance.rb,
lib/rcb/state_store.rb,
lib/rcb/configuration.rb

Defined Under Namespace

Modules: ClassMethods, Configurations, DSL, Result, State, StateStore Classes: CircuitBreakerOpenError, Instance

Constant Summary collapse

OpenCondition =
Rstruct.new(:max_failure_count, :window_msec) do
  self::DEFAULT = new(3, 1000).freeze
end
Config =
Rstruct.new(:tag, :open_condition, :reset_timeout_msec) do
  self::RESET_TIMEOUT_MSEC = 1000.freeze

  @logger = Logger.new($stderr)

  def self.create(tag, open_condition: nil, reset_timeout_msec: nil)
    raise 'Rcb tag must not be nil' if tag.nil?

    if open_condition.nil? && reset_timeout_msec.nil?
      @logger.warn("Rcb for '#{tag}' is not configured!")
    end

    Config.new(
      tag.to_s.to_sym,
      open_condition || OpenCondition::DEFAULT,
      reset_timeout_msec || Config::RESET_TIMEOUT_MSEC
    )
  end
end

Class Method Summary collapse

Methods included from ClassMethods

for

Class Method Details

.configure(tag, &block) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/rcb/configuration.rb', line 81

def Rcb.configure(tag, &block)
  c = DSL::ConfigBuilder.new(tag.to_s.to_sym)
        .tap { |cb| block.call(cb) }
        .build

  Configurations.add(c)
end