Class: Resilient::CircuitBreaker::Properties
- Inherits:
-
Object
- Object
- Resilient::CircuitBreaker::Properties
- Defined in:
- lib/resilient/circuit_breaker/properties.rb
Instance Attribute Summary collapse
-
#bucket_size_in_seconds ⇒ Object
readonly
size of buckets in statistical window.
-
#error_threshold_percentage ⇒ Object
readonly
% of “marks” that must be failed to trip the circuit.
-
#force_closed ⇒ Object
readonly
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 ⇒ Object
readonly
allows forcing the circuit open (stopping all requests).
-
#instrumenter ⇒ Object
readonly
what to use to instrument all events that happen (ie: ActiveSupport::Notifications).
-
#metrics ⇒ Object
readonly
metrics instance used to keep track of success and failure.
-
#request_volume_threshold ⇒ Object
readonly
number of requests that must be made within a statistical window before open/close decisions are made using stats.
-
#sleep_window_seconds ⇒ Object
readonly
seconds after tripping circuit before allowing retry.
-
#window_size_in_seconds ⇒ Object
readonly
number of seconds in the statistical window.
Class Method Summary collapse
-
.wrap(hash_or_instance) ⇒ Object
Internal: Takes a string name or instance of a Key and always returns a Key instance.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Properties
constructor
A new instance of Properties.
Constructor Details
#initialize(options = {}) ⇒ Properties
Returns a new instance of Properties.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 53 def initialize( = {}) @force_open = .fetch(:force_open, false) @force_closed = .fetch(:force_closed, false) @instrumenter = .fetch(:instrumenter, Instrumenters::Noop) @sleep_window_seconds = .fetch(:sleep_window_seconds, 5) @request_volume_threshold = .fetch(:request_volume_threshold, 20) @error_threshold_percentage = .fetch(:error_threshold_percentage, 50) @window_size_in_seconds = .fetch(:window_size_in_seconds, 60) @bucket_size_in_seconds = .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 = .fetch(:metrics) { Metrics.new({ window_size_in_seconds: @window_size_in_seconds, bucket_size_in_seconds: @bucket_size_in_seconds, }) } end |
Instance Attribute Details
#bucket_size_in_seconds ⇒ Object (readonly)
size of buckets in statistical window
48 49 50 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 48 def bucket_size_in_seconds @bucket_size_in_seconds end |
#error_threshold_percentage ⇒ Object (readonly)
% of “marks” that must be failed to trip the circuit
42 43 44 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 42 def error_threshold_percentage @error_threshold_percentage end |
#force_closed ⇒ Object (readonly)
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
28 29 30 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 28 def force_closed @force_closed end |
#force_open ⇒ Object (readonly)
allows forcing the circuit open (stopping all requests)
23 24 25 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 23 def force_open @force_open end |
#instrumenter ⇒ Object (readonly)
what to use to instrument all events that happen (ie: ActiveSupport::Notifications)
32 33 34 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 32 def instrumenter @instrumenter end |
#metrics ⇒ Object (readonly)
metrics instance used to keep track of success and failure
51 52 53 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 51 def metrics @metrics end |
#request_volume_threshold ⇒ Object (readonly)
number of requests that must be made within a statistical window before open/close decisions are made using stats
39 40 41 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 39 def request_volume_threshold @request_volume_threshold end |
#sleep_window_seconds ⇒ Object (readonly)
seconds after tripping circuit before allowing retry
35 36 37 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 35 def sleep_window_seconds @sleep_window_seconds end |
#window_size_in_seconds ⇒ Object (readonly)
number of seconds in the statistical window
45 46 47 |
# File 'lib/resilient/circuit_breaker/properties.rb', line 45 def window_size_in_seconds @window_size_in_seconds end |
Class Method Details
.wrap(hash_or_instance) ⇒ Object
Internal: Takes a string name or instance of a Key and always returns a Key instance.
9 10 11 12 13 14 15 16 17 18 19 20 |
# 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 |