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_afterwhen 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.
-
#error_mapper ⇒ Module, #call
readonly
Used by patches to set the namespace module for the faulty errors that will be raised.
-
#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.
-
#registry ⇒ CircuitRegistry
readonly
memoization of circuits.
-
#sample_threshold ⇒ Integer
readonly
The minimum number of runs required before a circuit can trip.
-
#storage ⇒ Storage::Interface
readonly
Storage::Memory.new.
Instance Method Summary collapse
- #defaults ⇒ Object
- #finalize ⇒ Object
-
#for_storage ⇒ Hash
Get the options stored in the storage backend.
- #required ⇒ Object
Methods included from ImmutableOptions
#dup_with, #initialize, #setup
Instance Attribute Details
#cache ⇒ Cache::Interface (readonly)
Cache::Null.new. Unlike Faulty#initialize, this is not wrapped in
Faulty::Cache::AutoWire by default.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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 |
#error_mapper ⇒ Module, #call (readonly)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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 |
#registry ⇒ CircuitRegistry (readonly)
memoization of circuits.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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)
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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.
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/faulty/circuit.rb', line 91 Options = Struct.new( :cache_expires_in, :cache_refreshes_after, :cache_refresh_jitter, :cool_down, :evaluation_window, :rate_threshold, :sample_threshold, :errors, :error_mapper, :exclude, :cache, :notifier, :storage, :registry ) do include ImmutableOptions # Get the options stored in the storage backend # # @return [Hash] A hash of stored options def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end def required i[ cache cool_down errors error_mapper 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 |
Instance Method Details
#defaults ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/faulty/circuit.rb', line 121 def defaults { cache_expires_in: 86_400, cache_refreshes_after: 900, cool_down: 300, errors: [StandardError], error_mapper: Faulty, exclude: [], evaluation_window: 60, rate_threshold: 0.5, sample_threshold: 3 } end |
#finalize ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/faulty/circuit.rb', line 150 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 |
#for_storage ⇒ Hash
Get the options stored in the storage backend
112 113 114 115 116 117 118 119 |
# File 'lib/faulty/circuit.rb', line 112 def for_storage { cool_down: cool_down, evaluation_window: evaluation_window, rate_threshold: rate_threshold, sample_threshold: sample_threshold } end |
#required ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/faulty/circuit.rb', line 135 def required i[ cache cool_down errors error_mapper exclude evaluation_window rate_threshold sample_threshold notifier storage ] end |