Method: MysqlFramework::Scripts::LockManager#with_lock
- Defined in:
- lib/mysql_framework/scripts/lock_manager.rb
#with_lock(key:, ttl: default_ttl, max_attempts: default_max_retries, retry_delay: default_retry_delay) ⇒ Object
This method is called to request and release a lock around yielding to a user supplied block
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mysql_framework/scripts/lock_manager.rb', line 53 def with_lock(key:, ttl: default_ttl, max_attempts: default_max_retries, retry_delay: default_retry_delay) raise 'Block must be specified.' unless block_given? begin lock = request_lock(key: key, ttl: ttl, max_attempts: max_attempts, retry_delay: retry_delay) yield ensure release_lock(key: key, lock: lock) end end |