Class: MotherBrain::LockManager
- Inherits:
-
Object
- Object
- MotherBrain::LockManager
- Includes:
- Celluloid, Logging
- Defined in:
- lib/mb/lock_manager.rb
Overview
A registry of locks obtained against resources on a Chef Server
Instance Attribute Summary collapse
- #locks ⇒ Set<ChefMutex> readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#async_lock(environment) ⇒ MB::JobRecord
Asynchronously lock an environment.
-
#async_unlock(environment) ⇒ MB::JobRecord
Asynchronously unlock an environment.
-
#find(options) ⇒ ChefMutex?
Find a lock of the given name in the list of registered locks.
-
#initialize ⇒ LockManager
constructor
A new instance of LockManager.
-
#lock(job, environment) ⇒ Boolean
Lock an environment.
-
#register(mutex) ⇒ Object
Register the given lock.
- #reset ⇒ Object
-
#unlock(job, environment) ⇒ Boolean
Unlock an environment.
-
#unregister(mutex) ⇒ Object
Unregister the given lock.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
#initialize ⇒ LockManager
Returns a new instance of LockManager.
21 22 23 24 |
# File 'lib/mb/lock_manager.rb', line 21 def initialize log.debug { "Lock Manager starting..." } @locks = Set.new end |
Instance Attribute Details
#locks ⇒ Set<ChefMutex> (readonly)
17 18 19 |
# File 'lib/mb/lock_manager.rb', line 17 def locks @locks end |
Class Method Details
.instance ⇒ Celluloid::Actor(LockManager)
8 9 10 |
# File 'lib/mb/lock_manager.rb', line 8 def instance MB::Application[:lock_manager] or raise Celluloid::DeadActorError, "lock manager not running" end |
Instance Method Details
#async_lock(environment) ⇒ MB::JobRecord
Asynchronously lock an environment
63 64 65 66 67 |
# File 'lib/mb/lock_manager.rb', line 63 def async_lock(environment) job = Job.new(:lock) async(:lock, job, environment) job.ticket end |
#async_unlock(environment) ⇒ MB::JobRecord
Asynchronously unlock an environment
89 90 91 92 93 |
# File 'lib/mb/lock_manager.rb', line 89 def async_unlock(environment) job = Job.new(:unlock) async(:unlock, job, environment) job.ticket end |
#find(options) ⇒ ChefMutex?
Find a lock of the given name in the list of registered locks
31 32 33 34 35 36 37 38 |
# File 'lib/mb/lock_manager.rb', line 31 def find() type, name = .to_a.flatten locks.find { |mutex| mutex.type == type && mutex.name == name } end |
#lock(job, environment) ⇒ Boolean
Lock an environment
75 76 77 78 79 80 81 82 |
# File 'lib/mb/lock_manager.rb', line 75 def lock(job, environment) ChefMutex.new( chef_environment: environment, force: true, job: job, report_job_status: true ).lock end |
#register(mutex) ⇒ Object
Register the given lock
43 44 45 |
# File 'lib/mb/lock_manager.rb', line 43 def register(mutex) locks.add(mutex) end |
#reset ⇒ Object
47 48 49 |
# File 'lib/mb/lock_manager.rb', line 47 def reset self.locks.clear end |
#unlock(job, environment) ⇒ Boolean
Unlock an environment
101 102 103 104 105 106 107 108 |
# File 'lib/mb/lock_manager.rb', line 101 def unlock(job, environment) ChefMutex.new( chef_environment: environment, force: true, job: job, report_job_status: true ).unlock end |
#unregister(mutex) ⇒ Object
Unregister the given lock
54 55 56 |
# File 'lib/mb/lock_manager.rb', line 54 def unregister(mutex) locks.delete(mutex) end |