Class: Aws::Waiters::Waiter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/waiters/waiter.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

RAISE_HANDLER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Seahorse::Client::Plugins::RaiseResponseErrors::Handler

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Waiter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Waiter



10
11
12
13
14
15
16
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 10

def initialize(options = {})
  @poller = options[:poller]
  @max_attempts = options[:max_attempts]
  @delay = options[:delay]
  @before_attempt = Array(options[:before_attempt])
  @before_wait = Array(options[:before_wait])
end

Instance Attribute Details

#delayFloat Also known as: interval

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Float)


25
26
27
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 25

def delay
  @delay
end

#max_attemptsInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)


22
23
24
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 22

def max_attempts
  @max_attempts
end

#pollerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 19

def poller
  @poller
end

Instance Method Details

#before_attempt {|attempts| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a callback that is invoked before every polling attempt. Yields the number of attempts made so far.

waiter.before_attempt do |attempts|
  puts "#{attempts} made, about to make attempt #{attempts + 1}"
end

Throwing `:success` or `:failure` from the given block will stop the waiter and return or raise. You can pass a custom message to the throw:

# raises Aws::Waiters::Errors::WaiterFailed
waiter.before_attempt do |attempts|
  throw :failure, 'custom-error-message'
end

# cause the waiter to stop polling and return
waiter.before_attempt do |attempts|
  throw :success
end

Yield Parameters:

  • attempts (Integer)

    The number of attempts made.



52
53
54
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 52

def before_attempt(&block)
  @before_attempt << Proc.new
end

#before_wait {|attempts, response| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Register a callback that is invoked after an attempt but before sleeping. Yields the number of attempts made and the previous response.

waiter.before_wait do |attempts, response|
  puts "#{attempts} made"
  puts response.error.inspect
  puts response.data.inspect
end

Throwing `:success` or `:failure` from the given block will stop the waiter and return or raise. You can pass a custom message to the throw:

# raises Aws::Waiters::Errors::WaiterFailed
waiter.before_attempt do |attempts|
  throw :failure, 'custom-error-message'
end

# cause the waiter to stop polling and return
waiter.before_attempt do |attempts|
  throw :success
end

Yield Parameters:

  • attempts (Integer)

    The number of attempts already made.

  • response (Seahorse::Client::Response)

    The response from the previous polling attempts.



83
84
85
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 83

def before_wait(&block)
  @before_wait << Proc.new
end

#wait(options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :client (Client)
  • :params (Hash)


89
90
91
92
93
94
95
96
# File 'lib/aws-sdk-core/waiters/waiter.rb', line 89

def wait(options)
  catch(:success) do
    failure_msg = catch(:failure) do
      return poll(options)
    end
    raise Errors::WaiterFailed.new(failure_msg || 'waiter failed')
  end || true
end