Class: Faulty::Storage::FaultTolerantProxy
- Inherits:
-
Object
- Object
- Faulty::Storage::FaultTolerantProxy
- Defined in:
- lib/faulty/storage/fault_tolerant_proxy.rb
Overview
A wrapper for storage backends that may raise errors
Faulty::Scope 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.
Instance Method Summary collapse
-
#close(circuit) ⇒ Boolean
Safely mark a circuit as closed.
-
#entry(circuit, time, success) ⇒ Status
Add a history entry safely.
-
#fault_tolerant? ⇒ true
This cache makes any storage fault tolerant, so this is always
true. -
#history(circuit) ⇒ Array<Array>
Since history is not called in normal operation, it does not capture errors.
-
#initialize(storage, **options) {|Options| ... } ⇒ FaultTolerantProxy
constructor
A new instance of FaultTolerantProxy.
-
#list ⇒ Array<String>
Safely get the list of circuit names.
-
#lock(circuit, state) ⇒ void
Since lock is not called in normal operation, it does not 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) ⇒ void
Since reset is not called in normal operation, it does not capture errors.
-
#status(circuit) ⇒ Status
Safely get the status of a circuit.
-
#unlock(circuit) ⇒ void
Since unlock is not called in normal operation, it does not 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.
13 14 15 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 13 def @options end |
Instance Method Details
#close(circuit) ⇒ Boolean
Safely mark a circuit as closed
80 81 82 83 84 85 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 80 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
Add a history entry safely
44 45 46 47 48 49 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 44 def entry(circuit, time, success) @storage.entry(circuit, time, success) rescue StandardError => e .notifier.notify(:storage_failure, circuit: circuit, action: :entry, error: e) stub_status(circuit) end |
#fault_tolerant? ⇒ true
This cache makes any storage fault tolerant, so this is always true
159 160 161 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 159 def fault_tolerant? true end |
#history(circuit) ⇒ Array<Array>
Since history is not called in normal operation, it does not capture errors
138 139 140 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 138 def history(circuit) @storage.history(circuit) end |
#list ⇒ Array<String>
Safely get the list of circuit names
If the backend is unavailable, this returns an empty array
149 150 151 152 153 154 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 149 def list @storage.list rescue StandardError => e .notifier.notify(:storage_failure, action: :list, error: e) [] end |
#lock(circuit, state) ⇒ void
This method returns an undefined value.
Since lock is not called in normal operation, it does not capture errors
93 94 95 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 93 def lock(circuit, state) @storage.lock(circuit, state) end |
#open(circuit, opened_at) ⇒ Boolean
Safely mark a circuit as open
56 57 58 59 60 61 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 56 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
68 69 70 71 72 73 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 68 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) ⇒ void
This method returns an undefined value.
Since reset is not called in normal operation, it does not capture errors
113 114 115 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 113 def reset(circuit) @storage.reset(circuit) 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.
125 126 127 128 129 130 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 125 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) ⇒ void
This method returns an undefined value.
Since unlock is not called in normal operation, it does not capture errors
103 104 105 |
# File 'lib/faulty/storage/fault_tolerant_proxy.rb', line 103 def unlock(circuit) @storage.unlock(circuit) end |