Module: Bosh::Common
- Defined in:
- lib/common/common.rb,
lib/common/errors.rb,
lib/common/version.rb,
lib/common/deep_copy.rb,
lib/common/version/bosh_version.rb,
lib/common/version/version_list.rb,
lib/common/version/release_version.rb,
lib/common/version/stemcell_version.rb,
lib/common/version/release_version_list.rb,
lib/common/version/semi_semantic_version.rb,
lib/common/version/stemcell_version_list.rb
Overview
Module for common methods used throughout the BOSH code.
Defined Under Namespace
Modules: DeepCopy, Release, Version Classes: RetryCountExceeded
Constant Summary collapse
- VERSION =
'1.3262.24.0'
Class Method Summary collapse
-
.retryable(options = {}, &block) ⇒ Object
Retries execution of given block until block returns true.
-
.symbolize_keys(hash) ⇒ Hash
Converts all keys of a [Hash] to symbols.
- .which(programs, path = ) ⇒ Object
Class Method Details
.retryable(options = {}, &block) ⇒ Object
Retries execution of given block until block returns true
The block is called with two parameters: the number of tries and the most recent exception. If the block returns true retrying is stopped. Examples:
Bosh::Common.retryable do |retries, exception|
puts "try #{retries} failed with exception: #{exception}" if retries > 0
pick_up_soap
end
# Wait for EC2 instance to be terminated
Bosh::Common.retryable(on: AWS::EC2::Errors::RequestLimitExceeded) do |retries, exception|
@ec2.instance['i-a3x5g5'].status == :terminated
end
end
Bosh::Common.retryable(ensure: ensure_cb) do
# process file
end
118 119 120 |
# File 'lib/common/common.rb', line 118 def retryable( = {}, &block) Bosh::Retryable.new().retryer(&block) end |
.symbolize_keys(hash) ⇒ Hash
Converts all keys of a [Hash] to symbols. Performs deep conversion.
14 15 16 17 18 19 |
# File 'lib/common/common.rb', line 14 def symbolize_keys(hash) hash.inject({}) do |h, (key, value)| h[key.to_sym] = value.is_a?(Hash) ? symbolize_keys(value) : value h end end |
.which(program, path) ⇒ String .which(programs, path) ⇒ String
37 38 39 40 41 42 43 44 45 |
# File 'lib/common/common.rb', line 37 def which(programs, path=ENV["PATH"]) path.split(File::PATH_SEPARATOR).each do |dir| Array(programs).each do |bin| exe = File.join(dir, bin) return exe if File.executable?(exe) end end nil end |