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

Instance Method Details

#chef_lock(options = {}) ⇒ Boolean

Attempts to create a lock. Fails if the lock already exists.

Returns:

  • (Boolean)

Raises:

See Also:



19
20
21
# File 'lib/mb/mixin/locks.rb', line 19

def chef_lock(options = {})
  find_or_new(options).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.

Returns:

  • (Boolean)

Raises:

See Also:



32
33
34
# File 'lib/mb/mixin/locks.rb', line 32

def chef_synchronize(options = {}, &block)
  ChefMutex.synchronize(options, &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

Raises:

See Also:



43
44
45
# File 'lib/mb/mixin/locks.rb', line 43

def chef_unlock(options = {})
  find_or_new(options).unlock
end