Module: Bosh::Director::LockHelper
- Included in:
- DeploymentPlan::Assembler, DeploymentPlan::Planner, DeploymentPlan::Steps::PackageCompileStep, Jobs::CleanupArtifacts, Jobs::CloudCheck::ApplyResolutions, Jobs::CloudCheck::Scan, Jobs::CloudCheck::ScanAndFix, Jobs::DeleteDeployment, Jobs::DeleteRelease, Jobs::ExportRelease, Jobs::FetchLogs, Jobs::Helpers::StemcellDeleter, Jobs::RunErrand, Jobs::UpdateDeployment, Jobs::UpdateRelease
- Defined in:
- lib/bosh/director/lock_helper.rb
Instance Method Summary collapse
- #with_compile_lock(package_id, stemcell_id, opts = {}) ⇒ Object
- #with_deployment_lock(deployment, opts = {}) ⇒ Object
- #with_release_lock(release_name, opts = {}) ⇒ Object
- #with_release_locks(release_names, opts = {}) ⇒ Object
- #with_stemcell_lock(name, version, opts = {}) ⇒ Object
Instance Method Details
#with_compile_lock(package_id, stemcell_id, opts = {}) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/bosh/director/lock_helper.rb', line 42 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 = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/bosh/director/lock_helper.rb', line 3 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_name, opts = {}) ⇒ Object
23 24 25 |
# File 'lib/bosh/director/lock_helper.rb', line 23 def with_release_lock(release_name, opts = {}) with_release_locks([release_name], opts) { yield } end |
#with_release_locks(release_names, opts = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bosh/director/lock_helper.rb', line 27 def with_release_locks(release_names, opts = {}) timeout = opts[:timeout] || 10 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 = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/bosh/director/lock_helper.rb', line 16 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 |