class Resilient::CircuitBreaker::Properties

Attributes

bucket_size_in_seconds[R]

size of buckets in statistical window

error_threshold_percentage[R]

% of “marks” that must be failed to trip the circuit

force_closed[R]

allows ignoring errors and therefore never trip “open” (ie. allow all traffic through); normal instrumentation will still happen, thus allowing you to “test” configuration live without impact

force_open[R]

allows forcing the circuit open (stopping all requests)

instrumenter[R]

what to use to instrument all events that happen (ie: ActiveSupport::Notifications)

metrics[R]

metrics instance used to keep track of success and failure

request_volume_threshold[R]

number of requests that must be made within a statistical window before open/close decisions are made using stats

sleep_window_seconds[R]

seconds after tripping circuit before allowing retry

window_size_in_seconds[R]

number of seconds in the statistical window

Public Class Methods

new(options = {}) click to toggle source
# File lib/resilient/circuit_breaker/properties.rb, line 53
def initialize(options = {})
  @force_open = options.fetch(:force_open, false)
  @force_closed = options.fetch(:force_closed, false)
  @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
  @sleep_window_seconds = options.fetch(:sleep_window_seconds, 5)
  @request_volume_threshold = options.fetch(:request_volume_threshold, 20)
  @error_threshold_percentage = options.fetch(:error_threshold_percentage, 50)
  @window_size_in_seconds = options.fetch(:window_size_in_seconds, 60)
  @bucket_size_in_seconds = options.fetch(:bucket_size_in_seconds, 10)

  if @bucket_size_in_seconds >= @window_size_in_seconds
    raise ArgumentError, "bucket_size_in_seconds must be smaller than window_size_in_seconds"
  end

  if @window_size_in_seconds % @bucket_size_in_seconds != 0
    raise ArgumentError,
      "window_size_in_seconds must be perfectly divisible by" +
      " bucket_size_in_seconds in order to evenly partition the buckets"
  end

  @metrics = options.fetch(:metrics) {
    Metrics.new({
      window_size_in_seconds: @window_size_in_seconds,
      bucket_size_in_seconds: @bucket_size_in_seconds,
    })
  }
end
wrap(hash_or_instance) click to toggle source

Internal: Takes a string name or instance of a Key and always returns a Key instance.

# File lib/resilient/circuit_breaker/properties.rb, line 9
def self.wrap(hash_or_instance)
  case hash_or_instance
  when self
    hash_or_instance
  when Hash
    new(hash_or_instance)
  when NilClass
    new
  else
    raise TypeError, "properties must be Hash or Resilient::Properties instance"
  end
end