Class: Faulty::Circuit::Options
- Inherits:
-
Struct
- Object
- Struct
- Faulty::Circuit::Options
- Includes:
- ImmutableOptions
- Defined in:
- lib/faulty/circuit.rb
Overview
Options for Faulty::Circuit
Instance Attribute Summary collapse
-
#cache ⇒ Cache::Interface
readonly
Cache::Null.new
. -
#cache_expires_in ⇒ Integer?
readonly
The number of seconds to keep cached results.
-
#cache_refresh_jitter ⇒ Integer
readonly
The maximum number of seconds to randomly add or subtract from
cache_refreshes_after
when determining whether to refresh the cache. -
#cache_refreshes_after ⇒ Integer?
readonly
The number of seconds after which we attempt to refresh the cache even if it's not expired.
-
#cool_down ⇒ Integer
readonly
The number of seconds the circuit will stay open after it is tripped.
-
#errors ⇒ Error+
readonly
An array of errors that are considered circuit failures.
-
#evaluation_window ⇒ Integer
readonly
The number of seconds of history that will be evaluated to determine the failure rate for a circuit.
-
#exclude ⇒ Error+
readonly
An array of errors that will not be captured by Faulty.
-
#notifier ⇒ Events::Notifier
readonly
A Faulty notifier.
-
#rate_threshold ⇒ Float
readonly
The minimum failure rate required to trip the circuit.
-
#sample_threshold ⇒ Integer
readonly
The minimum number of runs required before a circuit can trip.
-
#storage ⇒ Storage::Interface
readonly
Storage::Memory.new
.
Method Summary
Methods included from ImmutableOptions
Instance Attribute Details
#cache ⇒ Cache::Interface (readonly)
Cache::Null.new
. Unlike Faulty#initialize, this is not wrapped in
Faulty::Cache::AutoWire by default.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#cache_expires_in ⇒ Integer? (readonly)
Returns The number of seconds to keep
cached results. A value of nil will keep the cache indefinitely.
Default 86400
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#cache_refresh_jitter ⇒ Integer (readonly)
Returns The maximum number of seconds to randomly add or
subtract from cache_refreshes_after
when determining whether to
refresh the cache. A non-zero value helps reduce a "thundering herd"
cache refresh in most scenarios. Set to 0
to disable jitter.
Default 0.2 * cache_refreshes_after
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#cache_refreshes_after ⇒ Integer? (readonly)
Returns The number of seconds after which we attempt
to refresh the cache even if it's not expired. If the circuit fails,
we continue serving the value from cache until cache_expires_in
.
A value of nil
disables cache refreshing.
Default 900
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#cool_down ⇒ Integer (readonly)
Returns The number of seconds the circuit will stay open after it is tripped. Default 300.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#errors ⇒ Error+ (readonly)
Returns An array of errors that are considered circuit
failures. Default [StandardError]
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#evaluation_window ⇒ Integer (readonly)
Returns The number of seconds of history that
will be evaluated to determine the failure rate for a circuit.
Default 60
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#exclude ⇒ Error+ (readonly)
Returns An array of errors that will not be
captured by Faulty. These errors will not be considered circuit
failures. Default []
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#notifier ⇒ Events::Notifier (readonly)
Returns A Faulty notifier. Default Events::Notifier.new
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#rate_threshold ⇒ Float (readonly)
Returns The minimum failure rate required to trip
the circuit. For example, 0.5
requires at least a 50% failure rate to
trip. Default 0.5
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#sample_threshold ⇒ Integer (readonly)
Returns The minimum number of runs required before
a circuit can trip. A value of 1 means that the circuit will trip
immediately when a failure occurs. Default 3
.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |
#storage ⇒ Storage::Interface (readonly)
Storage::Memory.new
. Unlike Faulty#initialize, this is not wrapped
in Storage::AutoWire by default.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/faulty/circuit.rb', line 82 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :exclude, :cache, :notifier, :storage ) do include ImmutableOptions private def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required %i[ cache cool_down errors exclude evaluation_window rate_threshold sample_threshold notifier storage ] end def finalize self.cache ||= Cache::Default.new self.notifier ||= Events::Notifier.new self.storage ||= Storage::Memory.new self.errors = [errors] if errors && !errors.is_a?(Array) self.exclude = [exclude] if exclude && !exclude.is_a?(Array) unless cache_refreshes_after.nil? self.cache_refresh_jitter = 0.2 * cache_refreshes_after end end end |