Class: Hyrax::LockManager
- Inherits:
-
Object
- Object
- Hyrax::LockManager
- Defined in:
- app/services/hyrax/lock_manager.rb
Defined Under Namespace
Classes: UnableToAcquireLockError
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 15 |
# File 'app/services/hyrax/lock_manager.rb', line 11 def initialize(time_to_live, retry_count, retry_delay) @ttl = time_to_live @retry_count = retry_count @retry_delay = retry_delay end |
Instance Method Details
#lock(key) ⇒ Object
Blocks until lock is acquired or timeout.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/hyrax/lock_manager.rb', line 19 def lock(key) returned_from_block = nil pool.then do |conn| client(conn).lock(key, @ttl) do |locked| raise UnableToAcquireLockError unless locked returned_from_block = yield end end returned_from_block rescue ConnectionPool::TimeoutError => err Hyrax.logger.error(err.) raise(ConnectionPool::TimeoutError, "Failed to acquire a lock from Redlock due to a Redis connection " \ "timeout: #{err}. If you are using Redis via `ConnectionPool` " \ "you may wish to increase the pool size.") end |