Class: Faulty::Storage::FallbackChain
- Inherits:
-
Object
- Object
- Faulty::Storage::FallbackChain
- Defined in:
- lib/faulty/storage/fallback_chain.rb
Overview
An prioritized list of storage backends
If any backend fails, the next will be tried until one succeeds. This should typically be used when using a fault-prone backend such as Redis.
This is used by Faulty#initialize if the storage
option is set to an
array.
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
Close a circuit in the first available storage backend.
-
#entry(circuit, time, success) ⇒ Array<Array>
Create a circuit entry in the first available storage backend.
-
#fault_tolerant? ⇒ Boolean
This is fault tolerant if any of the available backends are fault tolerant.
-
#history(circuit) ⇒ Array<Array>
Get the history of a circuit from the first available storage backend.
-
#initialize(storages, **options) {|Options| ... } ⇒ FallbackChain
constructor
Create a new FallbackChain to automatically fallback to reliable storage.
-
#list ⇒ Array<String>
Get the list of circuits from the first available storage backend.
-
#lock(circuit, state) ⇒ void
Lock a circuit in all storage backends.
-
#open(circuit, opened_at) ⇒ Boolean
Open a circuit in the first available storage backend.
-
#reopen(circuit, opened_at, previous_opened_at) ⇒ Boolean
Reopen a circuit in the first available storage backend.
-
#reset(circuit) ⇒ void
Reset a circuit in all storage backends.
-
#status(circuit) ⇒ Status
Get the status of a circuit from the first available storage backend.
-
#unlock(circuit) ⇒ void
Unlock a circuit in all storage backends.
Constructor Details
#initialize(storages, **options) {|Options| ... } ⇒ FallbackChain
Create a new Faulty::Storage::FallbackChain to automatically fallback to reliable storage
47 48 49 50 |
# File 'lib/faulty/storage/fallback_chain.rb', line 47 def initialize(storages, **, &block) @storages = storages @options = Options.new(, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/faulty/storage/fallback_chain.rb', line 22 def @options end |
Instance Method Details
#close(circuit) ⇒ Boolean
Close a circuit in the first available storage backend
86 87 88 89 90 |
# File 'lib/faulty/storage/fallback_chain.rb', line 86 def close(circuit) send_chain(:close, circuit) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :close, error: e) end end |
#entry(circuit, time, success) ⇒ Array<Array>
Create a circuit entry in the first available storage backend
56 57 58 59 60 |
# File 'lib/faulty/storage/fallback_chain.rb', line 56 def entry(circuit, time, success) send_chain(:entry, circuit, time, success) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :entry, error: e) end end |
#fault_tolerant? ⇒ Boolean
This is fault tolerant if any of the available backends are fault tolerant
150 151 152 |
# File 'lib/faulty/storage/fallback_chain.rb', line 150 def fault_tolerant? @storages.any?(&:fault_tolerant?) end |
#history(circuit) ⇒ Array<Array>
Get the history of a circuit from the first available storage backend
130 131 132 133 134 |
# File 'lib/faulty/storage/fallback_chain.rb', line 130 def history(circuit) send_chain(:history, circuit) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :history, error: e) end end |
#list ⇒ Array<String>
Get the list of circuits from the first available storage backend
140 141 142 143 144 |
# File 'lib/faulty/storage/fallback_chain.rb', line 140 def list send_chain(:list) do |e| .notifier.notify(:storage_failure, action: :list, error: e) end end |
#lock(circuit, state) ⇒ void
This method returns an undefined value.
Lock a circuit in all storage backends
96 97 98 |
# File 'lib/faulty/storage/fallback_chain.rb', line 96 def lock(circuit, state) send_all(:lock, circuit, state) end |
#open(circuit, opened_at) ⇒ Boolean
Open a circuit in the first available storage backend
66 67 68 69 70 |
# File 'lib/faulty/storage/fallback_chain.rb', line 66 def open(circuit, opened_at) send_chain(:open, circuit, opened_at) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :open, error: e) end end |
#reopen(circuit, opened_at, previous_opened_at) ⇒ Boolean
Reopen a circuit in the first available storage backend
76 77 78 79 80 |
# File 'lib/faulty/storage/fallback_chain.rb', line 76 def reopen(circuit, opened_at, previous_opened_at) send_chain(:reopen, circuit, opened_at, previous_opened_at) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :reopen, error: e) end end |
#reset(circuit) ⇒ void
This method returns an undefined value.
Reset a circuit in all storage backends
112 113 114 |
# File 'lib/faulty/storage/fallback_chain.rb', line 112 def reset(circuit) send_all(:reset, circuit) end |
#status(circuit) ⇒ Status
Get the status of a circuit from the first available storage backend
120 121 122 123 124 |
# File 'lib/faulty/storage/fallback_chain.rb', line 120 def status(circuit) send_chain(:status, circuit) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :status, error: e) end end |
#unlock(circuit) ⇒ void
This method returns an undefined value.
Unlock a circuit in all storage backends
104 105 106 |
# File 'lib/faulty/storage/fallback_chain.rb', line 104 def unlock(circuit) send_all(:unlock, circuit) end |