module MotherBrain::Mixin::Locks
A mixin to provide easy access to creating, destroying, and executing within locks in a running motherbrain application.
Public Instance Methods
Attempts to create a lock. Fails if the lock already exists.
@see ChefMutex#initialize
@raise [MotherBrain::InvalidLockType] if the lock type is invalid @raise [MotherBrain::ResourceLocked] if the lock is unobtainable
@return [Boolean]
# File lib/mb/mixin/locks.rb, line 19 def chef_lock(options = {}) find_or_new(options).lock end
Creates a new ChefMutex
on the given resource and runs the given block inside of it. The lock is released when the block completes.
@see ChefMutex#initialize
@raise [MotherBrain::InvalidLockType] if the lock type is invalid @raise [MotherBrain::ResourceLocked] if the lock is unobtainable
@return [Boolean]
# File lib/mb/mixin/locks.rb, line 32 def chef_synchronize(options = {}, &block) ChefMutex.synchronize(options, &block) end
Attempts to unlock the lock. Fails if the lock doesn’t exist, or if it is held by someone else
@see ChefMutex#initialize
@raise [MotherBrain::InvalidLockType] if the lock type is invalid @raise [MotherBrain::ResourceLocked] if the lock is owned by someone else
# File lib/mb/mixin/locks.rb, line 43 def chef_unlock(options = {}) find_or_new(options).unlock end
Private Instance Methods
# File lib/mb/mixin/locks.rb, line 49 def find_or_new(*args) find_lock(*args) || ChefMutex.new(*args) end