Sha256: 40e0196744222eb7ff00a78799a1d5e532373e4166750df4700615aa44a090b2

Contents?: true

Size: 945 Bytes

Versions: 13

Compression:

Stored size: 945 Bytes

Contents

require 'timeout'

module VagrantPlugins
  module Skytap
    module API
      module Busyable
        WAIT_TIMEOUT = 300
        WAIT_ITERATION_PERIOD = 2

        def update_with_retry(attrs, path=nil)
          retry_while_resource_busy do
            resp = api_client.put(path || url, JSON.dump(attrs))
            refresh(JSON.load(resp.body))
            break
          end
        end

        def retry_while_resource_busy(timeout=WAIT_TIMEOUT, &block)
          begin
            Timeout.timeout(timeout) do
              loop do
                break if env[:interrupted] # is this right?
                begin
                  yield
                rescue Errors::ResourceBusy
                end
                sleep WAIT_ITERATION_PERIOD
              end
            end
          rescue Timeout::Error => ex
            raise Errors::InstanceReadyTimeout, timeout: timeout
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
vagrant-skytap-0.2.3 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.2.2 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.2.1 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.2.0 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.11 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.10 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.9 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.8 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.7 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.6 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.5 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.4 lib/vagrant-skytap/api/busyable.rb
vagrant-skytap-0.1.3 lib/vagrant-skytap/api/busyable.rb