Class: AllMyCircuits::Strategies::NumberOverWindowStrategy

Inherits:
AbstractWindowStrategy show all
Defined in:
lib/all_my_circuits/strategies/number_over_window_strategy.rb

Overview

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

Instance Method Summary collapse

Methods inherited from AbstractWindowStrategy

#closed, #error, #opened, #success

Methods inherited from AbstractStrategy

#closed, #error, #opened, #success

Constructor Details

#initialize(failures_threshold:, **kwargs) ⇒ NumberOverWindowStrategy

Public: initializes a new instance.

Options

requests_window    - number of consecutive requests tracked by the window.
failures_threshold - number of failures within the window after which
                     the circuit is tripped open.


18
19
20
21
# File 'lib/all_my_circuits/strategies/number_over_window_strategy.rb', line 18

def initialize(failures_threshold:, **kwargs)
  @failures_threshold = failures_threshold
  super(**kwargs)
end

Instance Method Details

#should_open?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/all_my_circuits/strategies/number_over_window_strategy.rb', line 23

def should_open?
  return unless @window.full?

  failures = @window.count(:failed)
  failures >= @failures_threshold
end