class Aws::Waiters::Waiter
@api private
Constants
- RAISE_HANDLER
-
@api private
Attributes
@return [Float]
@return [Float]
@return [Float]
@return [Integer]
@api private
Public Class Methods
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 12 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
@api private
Public Instance Methods
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 54 def before_attempt(&block) @before_attempt << block if block_given? end
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
@yieldparam [Integer] attempts The number of attempts made.
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 85 def before_wait(&block) @before_wait << block if block_given? end
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
@yieldparam [Integer] attempts The number of attempts already made. @yieldparam [Seahorse::Client::Response] response The response from
the previous polling attempts.
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 91 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
@option options [Client] :client @option options [Hash] :params
Private Instance Methods
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 102 def poll(options) n = 0 loop do trigger_before_attempt(n) state, resp = @poller.call(options) n += 1 case state when :retry when :success then return resp when :failure then raise Errors::FailureStateError.new(resp) when :error then raise Errors::UnexpectedError.new(resp.error) end raise Errors::TooManyAttemptsError.new(n) if n == @max_attempts trigger_before_wait(n, resp) sleep(@delay) end end
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 124 def trigger_before_attempt(attempts) @before_attempt.each { |block| block.call(attempts) } end
Source
# File lib/aws-sdk-core/waiters/waiter.rb, line 128 def trigger_before_wait(attempts, response) @before_wait.each { |block| block.call(attempts, response) } end