class AllMyCircuits::Strategies::PercentageOverWindowStrategy

Public: opens the circuit whenever failures threshold is reached within the window. Threshold is represented by a percentage of failures within the window.

Public Class Methods

new(failure_rate_percent_threshold:, **kwargs) click to toggle source

Public: initializes a new instance.

Options

requests_window                - number of consecutive requests tracked by the window.
failure_rate_percent_threshold - percent rate of failures within the window after which
                                 the circuit is tripped open.
# File lib/all_my_circuits/strategies/percentage_over_window_strategy.rb, line 18
def initialize(failure_rate_percent_threshold:, **kwargs)
  @failure_rate_percent_threshold = failure_rate_percent_threshold
  super(**kwargs)
end

Public Instance Methods

should_open?() click to toggle source
# File lib/all_my_circuits/strategies/percentage_over_window_strategy.rb, line 23
def should_open?
  return false unless @window.full?

  failure_rate_percent = ((@window.count(:failed).to_f / @window.count) * 100).ceil
  failure_rate_percent >= @failure_rate_percent_threshold
end