Class: Faulty::Storage::FaultTolerantProxy
- Inherits:
-
Object
- Object
- Faulty::Storage::FaultTolerantProxy
- Extended by:
- Forwardable
- Defined in:
- lib/faulty/storage/fault_tolerant_proxy.rb
Overview
A wrapper for storage backends that may raise errors
Faulty#initialize automatically wraps all non-fault-tolerant storage backends with this class.
If the storage backend raises a StandardError
, it will be captured and
sent to the notifier.
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.wrap(storage, **options, &block) ⇒ Storage::Interface
Wrap a storage backend in a FaultTolerantProxy unless it's already fault tolerant.
Instance Method Summary collapse
-
#clear ⇒ Object
Clear is not called in normal operation, so it doesn't capture errors.
-
#close(circuit) ⇒ Boolean
Safely mark a circuit as closed.
-
#entry(circuit, time, success, status) ⇒ Status?
Add a history entry safely.
-
#fault_tolerant? ⇒ true
This cache makes any storage fault tolerant, so this is always
true
. -
#get_options(circuit) ⇒ Hash
Get circuit options safely.
-
#history(circuit) ⇒ Object
History is not called in normal operation, so it doesn't capture errors.
-
#initialize(storage, **options) {|Options| ... } ⇒ FaultTolerantProxy
constructor
A new instance of FaultTolerantProxy.
-
#list ⇒ Object
List is not called in normal operation, so it doesn't capture errors.
-
#lock(circuit, state) ⇒ Object
Lock is not called in normal operation, so it doesn't capture errors.
-
#open(circuit, opened_at) ⇒ Boolean
Safely mark a circuit as open.
-
#reopen(circuit, opened_at, previous_opened_at) ⇒ Boolean
Safely mark a circuit as reopened.
-
#reset(circuit) ⇒ Object
Reset is not called in normal operation, so it doesn't capture errors.
-
#set_options(circuit, stored_options) ⇒ void
Set circuit options safely.
-
#status(circuit) ⇒ Status
Safely get the status of a circuit.
-
#unlock(circuit) ⇒ Object
Unlock is not called in normal operation, so it doesn't capture errors.
Constructor Details
#initialize(storage, **options) {|Options| ... } ⇒ FaultTolerantProxy
Returns a new instance of FaultTolerantProxy.
34 35 36 37 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 34 def initialize(storage, **, &block) @storage = storage @options = Options.new(, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 15 def @options end |
Class Method Details
.wrap(storage, **options, &block) ⇒ Storage::Interface
Wrap a storage backend in a FaultTolerantProxy unless it's already fault tolerant
44 45 46 47 48 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 44 def self.wrap(storage, **, &block) return storage if storage.fault_tolerant? new(storage, **, &block) end |
Instance Method Details
#clear ⇒ Object
Clear is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |
#close(circuit) ⇒ Boolean
Safely mark a circuit as closed
158 159 160 161 162 163 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 158 def close(circuit) @storage.close(circuit) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :close, error: e) false end |
#entry(circuit, time, success, status) ⇒ Status?
Add a history entry safely
122 123 124 125 126 127 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 122 def entry(circuit, time, success, status) @storage.entry(circuit, time, success, status) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :entry, error: e) stub_status(circuit) if status end |
#fault_tolerant? ⇒ true
This cache makes any storage fault tolerant, so this is always true
183 184 185 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 183 def fault_tolerant? true end |
#get_options(circuit) ⇒ Hash
Get circuit options safely
98 99 100 101 102 103 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 98 def (circuit) @storage.(circuit) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :get_options, error: e) nil end |
#history(circuit) ⇒ Object
History is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |
#list ⇒ Object
List is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |
#lock(circuit, state) ⇒ Object
Lock is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |
#open(circuit, opened_at) ⇒ Boolean
Safely mark a circuit as open
134 135 136 137 138 139 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 134 def open(circuit, opened_at) @storage.open(circuit, opened_at) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :open, error: e) false end |
#reopen(circuit, opened_at, previous_opened_at) ⇒ Boolean
Safely mark a circuit as reopened
146 147 148 149 150 151 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 146 def reopen(circuit, opened_at, previous_opened_at) @storage.reopen(circuit, opened_at, previous_opened_at) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :reopen, error: e) false end |
#reset(circuit) ⇒ Object
Reset is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |
#set_options(circuit, stored_options) ⇒ void
This method returns an undefined value.
Set circuit options safely
110 111 112 113 114 115 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 110 def (circuit, ) @storage.(circuit, ) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :set_options, error: e) nil end |
#status(circuit) ⇒ Status
Safely get the status of a circuit
If the backend is unavailable, this returns a stub status that indicates that the circuit is closed.
173 174 175 176 177 178 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 173 def status(circuit) @storage.status(circuit) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :status, error: e) stub_status(circuit) end |
#unlock(circuit) ⇒ Object
Unlock is not called in normal operation, so it doesn't capture errors
91 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 91 def_delegators :@storage, :lock, :unlock, :reset, :history, :list, :clear |