Class: Stoplight::Infrastructure::Memory::DataStore::RecoveryLockStore
- Inherits:
-
Object
- Object
- Stoplight::Infrastructure::Memory::DataStore::RecoveryLockStore
- Defined in:
- lib/stoplight/infrastructure/memory/data_store/recovery_lock_store.rb
Overview
Process-local recovery lock using Ruby’s Thread::Mutex.
This only serializes recovery within a single Ruby process. Multiple processes/servers will NOT coordinate - each process can send probes independently.
Mutex Lifecycle:
-
One mutex created per unique light_name (lazily)
-
Mutexes persist for process lifetime (never GC’d)
Instance Method Summary collapse
- #acquire_lock(light_name) ⇒ Stoplight::Infrastructure::Memory::DataStore::RecoveryLockToken?
-
#initialize ⇒ RecoveryLockStore
constructor
A new instance of RecoveryLockStore.
- #release_lock(recovery_lock_token) ⇒ void
Constructor Details
#initialize ⇒ RecoveryLockStore
Returns a new instance of RecoveryLockStore.
20 21 22 |
# File 'lib/stoplight/infrastructure/memory/data_store/recovery_lock_store.rb', line 20 def initialize @locks = Concurrent::Map.new end |
Instance Method Details
#acquire_lock(light_name) ⇒ Stoplight::Infrastructure::Memory::DataStore::RecoveryLockToken?
26 27 28 29 |
# File 'lib/stoplight/infrastructure/memory/data_store/recovery_lock_store.rb', line 26 def acquire_lock(light_name) lock = lock_for(light_name) RecoveryLockToken.new(light_name:) if lock.try_lock end |
#release_lock(recovery_lock_token) ⇒ void
This method returns an undefined value.
33 34 35 |
# File 'lib/stoplight/infrastructure/memory/data_store/recovery_lock_store.rb', line 33 def release_lock(recovery_lock_token) lock_for(recovery_lock_token.light_name).unlock end |