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
-
#clear ⇒ void
Clears circuits in all storage backends.
-
#close(circuit) ⇒ Boolean
Close a circuit in the first available storage backend.
-
#entry(circuit, time, success, status) ⇒ Status?
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.
-
#get_options(circuit) ⇒ Hash
Get options from the first available storage backend.
-
#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.
-
#set_options(circuit, stored_options) ⇒ void
Try to set circuit options on all 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
45 46 47 48 |
# File 'lib/faulty/storage/fallback_chain.rb', line 45 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
#clear ⇒ void
This method returns an undefined value.
Clears circuits in all storage backends
166 167 168 |
# File 'lib/faulty/storage/fallback_chain.rb', line 166 def clear send_all(:clear) end |
#close(circuit) ⇒ Boolean
Close a circuit in the first available storage backend
102 103 104 105 106 |
# File 'lib/faulty/storage/fallback_chain.rb', line 102 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, status) ⇒ Status?
Create a circuit entry in the first available storage backend
72 73 74 75 76 |
# File 'lib/faulty/storage/fallback_chain.rb', line 72 def entry(circuit, time, success, status) send_chain(:entry, circuit, time, success, status) 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
174 175 176 |
# File 'lib/faulty/storage/fallback_chain.rb', line 174 def fault_tolerant? @storages.any?(&:fault_tolerant?) end |
#get_options(circuit) ⇒ Hash
Get options from the first available storage backend
54 55 56 57 58 |
# File 'lib/faulty/storage/fallback_chain.rb', line 54 def (circuit) send_chain(:get_options, circuit) do |e| .notifier.notify(:storage_failure, circuit: circuit, action: :get_options, error: e) end end |
#history(circuit) ⇒ Array<Array>
Get the history of a circuit from the first available storage backend
146 147 148 149 150 |
# File 'lib/faulty/storage/fallback_chain.rb', line 146 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
156 157 158 159 160 |
# File 'lib/faulty/storage/fallback_chain.rb', line 156 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
112 113 114 |
# File 'lib/faulty/storage/fallback_chain.rb', line 112 def lock(circuit, state) send_all(:lock, circuit, state) end |
#open(circuit, opened_at) ⇒ Boolean
Open a circuit in the first available storage backend
82 83 84 85 86 |
# File 'lib/faulty/storage/fallback_chain.rb', line 82 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
92 93 94 95 96 |
# File 'lib/faulty/storage/fallback_chain.rb', line 92 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
128 129 130 |
# File 'lib/faulty/storage/fallback_chain.rb', line 128 def reset(circuit) send_all(:reset, circuit) end |
#set_options(circuit, stored_options) ⇒ void
This method returns an undefined value.
Try to set circuit options on all backends
64 65 66 |
# File 'lib/faulty/storage/fallback_chain.rb', line 64 def (circuit, ) send_all(:set_options, circuit, ) end |
#status(circuit) ⇒ Status
Get the status of a circuit from the first available storage backend
136 137 138 139 140 |
# File 'lib/faulty/storage/fallback_chain.rb', line 136 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
120 121 122 |
# File 'lib/faulty/storage/fallback_chain.rb', line 120 def unlock(circuit) send_all(:unlock, circuit) end |