Class: Hyrax::LockManager
- Inherits:
-
Object
- Object
- Hyrax::LockManager
- Defined in:
- app/services/hyrax/lock_manager.rb
Defined Under Namespace
Classes: UnableToAcquireLockError
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
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
Returns a new instance of LockManager.
11 12 13 14 |
# File 'app/services/hyrax/lock_manager.rb', line 11 def initialize(time_to_live, retry_count, retry_delay) @ttl = time_to_live @client = Redlock::Client.new([Redis.current], retry_count: retry_count, retry_delay: retry_delay) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'app/services/hyrax/lock_manager.rb', line 6 def client @client end |
Instance Method Details
#lock(key) ⇒ Object
Blocks until lock is acquired or timeout.
17 18 19 20 21 22 23 24 |
# File 'app/services/hyrax/lock_manager.rb', line 17 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 |