Class: Stoplight::Infrastructure::FailSafe::Storage::RecoveryLock Private
- Inherits:
-
Object
- Object
- Stoplight::Infrastructure::FailSafe::Storage::RecoveryLock
- Defined in:
- lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb,
sig/_private/stoplight/infrastructure/fail_safe/storage/recovery_lock.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.
Constant Summary collapse
- Domain =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
-
#circuit_breaker ⇒ Domain::Light
readonly
private
The circuit breaker used to handle store failures.
- #error_notifier ⇒ error_notifier readonly private
-
#failover_store ⇒ Domain::_RecoveryLockStore
readonly
private
The fallback store used when the primary fails.
-
#primary_store ⇒ Domain::_RecoveryLockStore
readonly
private
The underlying primary store being used.
Instance Method Summary collapse
- #acquire_lock ⇒ RecoveryLockToken? private
-
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ RecoveryLock
constructor
private
A new instance of RecoveryLock.
-
#release_lock(recovery_lock_token) ⇒ void
private
Routes release to correct store based on token type.
- #wrap_token(origin, token) ⇒ Object private
Constructor Details
#initialize(primary_store:, error_notifier:, failover_store:, circuit_breaker:) ⇒ RecoveryLock
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 RecoveryLock.
21 22 23 24 25 26 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 21 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 ⇒ Domain::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.
The circuit breaker used to handle store failures.
60 61 62 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 60 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.
17 18 19 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 17 def error_notifier @error_notifier end |
#failover_store ⇒ Domain::_RecoveryLockStore (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.
The fallback store used when the primary fails.
19 20 21 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 19 def failover_store @failover_store end |
#primary_store ⇒ Domain::_RecoveryLockStore (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.
The underlying primary store being used
16 17 18 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 16 def primary_store @primary_store end |
Instance Method Details
#acquire_lock ⇒ RecoveryLockToken?
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.
28 29 30 31 32 33 34 35 36 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 28 def acquire_lock fallback = ->(error) { error_notifier.call(error) if error wrap_token(:failover, failover_store.acquire_lock) } circuit_breaker.run(fallback) do wrap_token(:primary, primary_store.acquire_lock) end end |
#release_lock(recovery_lock_token) ⇒ 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.
Routes release to correct store based on token type. Redis tokens release via primary (with error notification on failure). Memory tokens release via failover directly.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 42 def release_lock(recovery_lock_token) case recovery_lock_token.origin in :primary fallback = ->(error) { error_notifier.call(error) if error } circuit_breaker.run(fallback) do primary_store.release_lock(recovery_lock_token.) end in :failover failover_store.release_lock(recovery_lock_token.) end end |
#wrap_token(origin, token) ⇒ 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.
62 63 64 |
# File 'lib/stoplight/infrastructure/fail_safe/storage/recovery_lock.rb', line 62 def wrap_token(origin, token) RecoveryLockToken.new(origin:, underlying_token: token) if token end |