Module: Bosh::Director::LockHelper
- Included in:
- DeploymentPlan::Assembler, Jobs::CloudCheck::ApplyResolutions, Jobs::CloudCheck::Scan, Jobs::CloudCheck::ScanAndFix, Jobs::DeleteDeployment, Jobs::DeleteRelease, Jobs::DeleteStemcell, Jobs::FetchLogs, Jobs::RunErrand, Jobs::UpdateDeployment, Jobs::UpdateRelease, PackageCompiler
- Defined in:
- lib/bosh/director/lock_helper.rb
Overview
Helper for managing BOSH locks.
Instance Method Summary collapse
-
#with_compile_lock(package_id, stemcell_id, opts = {}) {|void| ... } ⇒ void
Surround with compile lock.
-
#with_deployment_lock(deployment, opts = {}) {|void| ... } ⇒ void
Surround with deployment lock.
-
#with_release_lock(release, opts = {}) {|void| ... } ⇒ void
Surround with release lock.
-
#with_release_locks(deployment_plan, opts = {}) {|void| ... } ⇒ void
Surround with deployment releases lock.
-
#with_stemcell_lock(name, version, opts = {}) {|void| ... } ⇒ void
Surround with stemcell lock.
Instance Method Details
#with_compile_lock(package_id, stemcell_id, opts = {}) {|void| ... } ⇒ void
This method returns an undefined value.
Surround with compile lock.
83 84 85 86 87 88 89 90 |
# File 'lib/bosh/director/lock_helper.rb', line 83 def with_compile_lock(package_id, stemcell_id, opts = {}) timeout = opts[:timeout] || 15 * 60 # 15 minutes Config.logger.info("Acquiring compile lock on " + "#{package_id} #{stemcell_id}") Lock.new("lock:compile:#{package_id}:#{stemcell_id}", :timeout => timeout).lock { yield } end |
#with_deployment_lock(deployment, opts = {}) {|void| ... } ⇒ void
This method returns an undefined value.
Surround with deployment lock.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bosh/director/lock_helper.rb', line 11 def with_deployment_lock(deployment, opts = {}) if deployment.respond_to?(:name) name = deployment.name elsif deployment.kind_of?(String) name = deployment else raise ArgumentError, "invalid deployment: #{deployment}" end timeout = opts[:timeout] || 10 Config.logger.info("Acquiring deployment lock on #{name}") Lock.new("lock:deployment:#{name}", :timeout => timeout).lock { yield } end |
#with_release_lock(release, opts = {}) {|void| ... } ⇒ void
This method returns an undefined value.
Surround with release lock.
44 45 46 47 48 |
# File 'lib/bosh/director/lock_helper.rb', line 44 def with_release_lock(release, opts = {}) timeout = opts[:timeout] || 10 Config.logger.info("Acquiring release lock on #{release}") Lock.new("lock:release:#{release}", :timeout => timeout).lock { yield } end |
#with_release_locks(deployment_plan, opts = {}) {|void| ... } ⇒ void
This method returns an undefined value.
Surround with deployment releases lock.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/bosh/director/lock_helper.rb', line 56 def with_release_locks(deployment_plan, opts = {}) timeout = opts[:timeout] || 10 release_names = deployment_plan.releases.map do |release| release.name end # Sorting to enforce lock order to avoid deadlocks locks = release_names.sort.map do |release_name| Config.logger.info("Acquiring release lock: #{release_name}") Lock.new("lock:release:#{release_name}", :timeout => timeout) end begin locks.each { |lock| lock.lock } yield ensure locks.reverse_each { |lock| lock.release } end end |
#with_stemcell_lock(name, version, opts = {}) {|void| ... } ⇒ void
This method returns an undefined value.
Surround with stemcell lock.
31 32 33 34 35 36 |
# File 'lib/bosh/director/lock_helper.rb', line 31 def with_stemcell_lock(name, version, opts = {}) timeout = opts[:timeout] || 10 Config.logger.info("Acquiring stemcell lock on #{name}:#{version}") Lock.new("lock:stemcells:#{name}:#{version}", :timeout => timeout). lock { yield } end |