class Aws::Waiters::Waiter
def acceptor_matches?(acceptor, resp)
def acceptor_matches?(acceptor, resp) case type(acceptor) when 'output' then output_matches?(resp, values(acceptor), path(acceptor)) when 'error' then error_matches?(resp.error, values(acceptor)) end end
def before_attempt(&block)
- Yieldparam: attempts - The number of attempts made.
def before_attempt(&block) @before_attempt << Proc.new end
def before_wait(&block)
- Yieldparam: response - The response from
Yieldparam: attempts - The number of attempts already made.
def before_wait(&block) @before_wait << Proc.new end
def error_ignored?(resp)
def error_ignored?(resp) if resp.error error_matches?(resp.error, @definition['ignore_errors'] || []) else true end end
def error_matches?(error, errors)
def error_matches?(error, errors) if error errors.any? { |pattern| error.class.name.match(/#{pattern}$/) } else false end end
def failure?(response)
def failure?(response) acceptor_matches?(:failure, response) end
def initialize(definition = {})
- Api: - private
def initialize(definition = {}) @definition = definition @interval = definition['interval'] @max_attempts = definition['max_attempts'] @before_attempt = [] @before_wait = [] end
def operation_name
def operation_name underscore(@definition['operation']).to_sym end
def output_matches?(resp, value, path)
def output_matches?(resp, value, path) if resp.error false elsif path output_value_matches?(value, Jamespath.search(path, resp.data)) else true end end
def output_value_matches?(expected, results)
def output_value_matches?(expected, results) if results.is_a?(Array) results.all? { |result| expected.include?(result) } else expected.include?(results) end end
def path(acceptor)
def path(acceptor) underscore(@definition["#{acceptor}_path"] || @definition['acceptor_path']) end
def send_request(client, params)
def send_request(client, params) req = client.build_request(operation_name, params) req.handlers.remove(RAISE_HANDLER) req.send_request end
def successful?(response)
def successful?(response) acceptor_matches?(:success, response) end
def too_many(attempts)
def too_many(attempts) "too many attempts made, #{attempts} attempts made without " + "success or failure" end
def trigger_callbacks(callbacks, *args)
def trigger_callbacks(callbacks, *args) callbacks.each { |block| block.call(*args) } end
def type(acceptor)
def type(acceptor) @definition["#{acceptor}_type"] || @definition['acceptor_type'] end
def underscore(str)
def underscore(str) str.gsub(/\w+/) { |part| Seahorse::Util.underscore(part) } if str end
def values(acceptor)
def values(acceptor) values = @definition["#{acceptor}_value"] || @definition['acceptor_value'] values.is_a?(Array) ? values : [values] end
def wait(client, params)
-
params
(Hash
) -- -
client
(Client
) --
def wait(client, params) attempts = 0 catch(:success) do failure = catch(:failure) do loop do trigger_callbacks(@before_attempt, attempts) attempts += 1 resp = send_request(client, params) throw :success, resp if successful?(resp) throw :failure if failure?(resp) throw :failure, resp.error unless error_ignored?(resp) throw :failure, too_many(attempts) if attempts == max_attempts trigger_callbacks(@before_wait, attempts, resp) sleep(interval) end end failure = 'waiter failed' if failure.nil? raise String === failure ? Errors::WaiterFailed.new(failure) : failure end end