class Aws::Waiters::Poller

Polls a single API operation inspecting the response data and/or error for states matching one of its acceptors. @api private

Constants

RAISE_HANDLER

@api private

Attributes

operation_name[R]

@return [Symbol]

Public Class Methods

new(options = {}) click to toggle source

@api private

# File lib/aws-sdk-core/waiters/poller.rb, line 13
def initialize(options = {})
  @operation_name = underscore(options['operation']).to_sym
  @acceptors = options['acceptors'] || []
end

Public Instance Methods

call(options = {}) click to toggle source

Makes an API call, returning the resultant state and the response.

  • `:success` - A success state has been matched.

  • `:failure` - A terminate failure state has been matched.

  • `:retry` - The waiter may be retried.

  • `:error` - The waiter encountered an un-expected error.

@example A trival (bad) example of a waiter that polls indefinetly.

loop do

  state, resp = poller.call(client:client, params:{})

  case state
  when :success then return true
  when :failure then return false
  when :retry   then next
  when :error   then raise 'oops'
  end

end

@option options [required,Client] :client @option options [required,Hash] :params @return [Array<Symbol,Response>]

# File lib/aws-sdk-core/waiters/poller.rb, line 46
def call(options = {})
  response = send_request(options)
  @acceptors.each do |acceptor|
    if acceptor_matches?(acceptor, response)
      return [acceptor['state'].to_sym, response]
    end
  end
  [response.error ? :error : :retry, response]
end

Private Instance Methods

acceptor_matches?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 64
def acceptor_matches?(acceptor, response)
  send("matches_#{acceptor['matcher']}?", acceptor, response)
end
matches_error?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 90
def matches_error?(acceptor, response)
  Aws::Errors::ServiceError === response.error &&
  response.error.code == acceptor['expected']
end
matches_path?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 68
def matches_path?(acceptor, response)
  JMESPath.search(path(acceptor), response.data) == acceptor['expected']
end
matches_pathAll?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 72
def matches_pathAll?(acceptor, response)
  values = JMESPath.search(path(acceptor), response.data)
  Array === values &&
    values.count > 0 &&
    values.all? { |value| value == acceptor['expected'] }
end
matches_pathAny?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 79
def matches_pathAny?(acceptor, response)
  values = JMESPath.search(path(acceptor), response.data)
  Array === values &&
    values.count > 0 &&
    values.any? { |value| value == acceptor['expected'] }
end
matches_status?(acceptor, response) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 86
def matches_status?(acceptor, response)
  response.context.http_response.status_code == acceptor['expected']
end
path(acceptor) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 95
def path(acceptor)
  acceptor['argument'].gsub(/\w+/) { |s| Seahorse::Util.underscore(s) }
end
send_request(options) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 58
def send_request(options)
  req = options[:client].build_request(@operation_name, options[:params])
  req.handlers.remove(RAISE_HANDLER)
  req.send_request
end
underscore(str) click to toggle source
# File lib/aws-sdk-core/waiters/poller.rb, line 99
def underscore(str)
  Seahorse::Util.underscore(str)
end