Sha256: 242c575afce9974c32849ed3eda966eb39342dfed881185d01e745b12b05b58a

Contents?: true

Size: 612 Bytes

Versions: 6

Compression:

Stored size: 612 Bytes

Contents

module ProfitBricks
  # Resource wait_for check
  def self.wait_for(timeout = ProfitBricks::Config.timeout,
                    interval = ProfitBricks::Config.interval,
                    &_block)
    duration = 0
    start = Time.now
    retries = 0
    until yield || duration > timeout
      sleep(interval.respond_to?(:call) ? interval.call(retries += 1).to_f : interval.to_f)
      duration = Time.now - start
    end
    if duration > timeout
      fail StandardError,
           "The specified wait_for timeout (#{timeout} seconds) was exceeded."
    else
      { duration: duration }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
profitbricks-sdk-ruby-4.0.1 lib/profitbricks/wait_for.rb
profitbricks-sdk-ruby-4.0.0 lib/profitbricks/wait_for.rb
profitbricks-sdk-ruby-3.0.2 lib/profitbricks/wait_for.rb
profitbricks-sdk-ruby-3.0.1 lib/profitbricks/wait_for.rb
profitbricks-sdk-ruby-3.0.0 lib/profitbricks/wait_for.rb
profitbricks-sdk-ruby-1.1.0 lib/profitbricks/wait_for.rb