Module: MotherBrain::Mixin::Locks
- Extended by:
- Forwardable
- Defined in:
- lib/mb/mixin/locks.rb
Overview
A mixin to provide easy access to creating, destroying, and executing within locks in a running motherbrain application.
Instance Method Summary collapse
-
#chef_lock(options = {}) ⇒ Boolean
Attempts to create a lock.
-
#chef_synchronize(options = {}, &block) ⇒ Boolean
Creates a new ChefMutex on the given resource and runs the given block inside of it.
-
#chef_unlock(options = {}) ⇒ Object
Attempts to unlock the lock.
Instance Method Details
#chef_lock(options = {}) ⇒ Boolean
Attempts to create a lock. Fails if the lock already exists.
19 20 21 |
# File 'lib/mb/mixin/locks.rb', line 19 def chef_lock( = {}) find_or_new().lock end |
#chef_synchronize(options = {}, &block) ⇒ Boolean
Creates a new ChefMutex on the given resource and runs the given block inside of it. The lock is released when the block completes.
32 33 34 |
# File 'lib/mb/mixin/locks.rb', line 32 def chef_synchronize( = {}, &block) ChefMutex.synchronize(, &block) end |
#chef_unlock(options = {}) ⇒ Object
Attempts to unlock the lock. Fails if the lock doesn’t exist, or if it is held by someone else
43 44 45 |
# File 'lib/mb/mixin/locks.rb', line 43 def chef_unlock( = {}) find_or_new().unlock end |