Class: Stoplight::Infrastructure::FailSafe::Storage::State Private
- Inherits:
-
Object
- Object
- Stoplight::Infrastructure::FailSafe::Storage::State
- Includes:
- Domain::_StateStore
- Defined in:
- lib/stoplight/infrastructure/fail_safe/storage/state.rb,
sig/_private/stoplight/infrastructure/fail_safe/storage/state.rbs
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A wrapper around a store that provides fail-safe mechanisms using a circuit breaker. It ensures that operations on the store can gracefully handle failures by falling back to default values when necessary.
Instance Attribute Summary collapse
- #circuit_breaker ⇒ _Light readonly private
- #error_notifier ⇒ error_notifier readonly private
- #failover_store ⇒ Domain::_StateStore readonly private
- #primary_store ⇒ Domain::_StateStore readonly private
Instance Method Summary collapse
- #clear ⇒ Object private
- #fallback(&fallback) ⇒ void private
-
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ State
constructor
private
A new instance of State.
- #set_state(state) ⇒ Object private
- #state_snapshot ⇒ Stoplight::Domain::StateSnapshot private
- #transition_to_color(color) ⇒ Boolean private
Constructor Details
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ State
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of State.
18 19 20 21 22 23 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 18 def initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) @primary_store = primary_store @error_notifier = error_notifier @failover_store = failover_store @circuit_breaker = circuit_breaker end |
Instance Attribute Details
#circuit_breaker ⇒ _Light (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 16 def circuit_breaker @circuit_breaker end |
#error_notifier ⇒ error_notifier (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 14 def error_notifier @error_notifier end |
#failover_store ⇒ Domain::_StateStore (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 15 def failover_store @failover_store end |
#primary_store ⇒ Domain::_StateStore (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 13 def primary_store @primary_store end |
Instance Method Details
#clear ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 46 def clear circuit_breaker.run(fallback { failover_store.clear }) do primary_store.clear end end |
#fallback(&fallback) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
52 53 54 55 56 57 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 52 private def fallback(&fallback) ->(error) { error_notifier.call(error) if error fallback.call } end |
#set_state(state) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 28 29 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 25 def set_state(state) circuit_breaker.run(fallback { failover_store.set_state(state) }) do primary_store.set_state(state) end end |
#state_snapshot ⇒ Stoplight::Domain::StateSnapshot
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 32 def state_snapshot circuit_breaker.run(fallback { failover_store.state_snapshot }) do primary_store.state_snapshot end end |
#transition_to_color(color) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/state.rb', line 40 def transition_to_color(color) circuit_breaker.run(fallback { failover_store.transition_to_color(color) }) do primary_store.transition_to_color(color) end end |