Class: Sufia::LockManager
- Inherits:
-
Object
- Object
- Sufia::LockManager
- Defined in:
- app/services/sufia/lock_manager.rb
Defined Under Namespace
Classes: UnableToAcquireLockError
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
TODO: This file is the same as curation_concerns/curation_concerns-models/app/services/curation_concerns/lock_manager.rb.
Instance Method Summary collapse
-
#initialize(time_to_live, retry_count, retry_delay) ⇒ LockManager
constructor
A new instance of LockManager.
-
#lock(key) ⇒ Object
Blocks until lock is acquired or timeout.
Constructor Details
#initialize(time_to_live, retry_count, retry_delay) ⇒ LockManager
14 15 16 17 |
# File 'app/services/sufia/lock_manager.rb', line 14 def initialize(time_to_live, retry_count, retry_delay) @ttl = time_to_live @client = Redlock::Client.new([uri], retry_count: retry_count, retry_delay: retry_delay) end |
Instance Attribute Details
#client ⇒ Object (readonly)
TODO: This file is the same as curation_concerns/curation_concerns-models/app/services/curation_concerns/lock_manager.rb.
During the merge of Sufia to use Curation Concerns, this file may be replaced by the Curation Concerns version.
9 10 11 |
# File 'app/services/sufia/lock_manager.rb', line 9 def client @client end |
Instance Method Details
#lock(key) ⇒ Object
Blocks until lock is acquired or timeout.
20 21 22 23 24 25 26 27 |
# File 'app/services/sufia/lock_manager.rb', line 20 def lock(key) returned_from_block = nil client.lock(key, @ttl) do |locked| raise UnableToAcquireLockError unless locked returned_from_block = yield end returned_from_block end |