class Envoi::Restore::SQSQueueWorker

Attributes

client[R]
config[R]
logger[R]
poller[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 9
def initialize(args = {})
  @config = args[:config] || args
  sqs_config = config
  @sqs_client_options = sqs_config['client_options'] || sqs_config
  @sqs_client_options = symbolize_keys(@sqs_client_options, true) if @sqs_client_options

  @sqs_poller_options = sqs_config['poller_options'] || {}
  @sqs_poller_options = symbolize_keys(@sqs_poller_options, true) if @sqs_poller_options

  @sqs_poll_options = sqs_config['poll_options'] || {}
  @sqs_poll_options = symbolize_keys(@sqs_poll_options, true) if @sqs_poll_options

  @sqs_poller_options[:queue_url] ||= sqs_config['queue_url']

  # puts "Client Options: #{@sqs_client_options}"
  # puts "Poller Options: #{@sqs_poller_options}"
  initialize_client
  initialize_poller
end
poll(args, &block) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 61
def self.poll(args, &block)
  handler = self.new(args)
  handler.poll(&block)
end

Public Instance Methods

initialize_client(args = @sqs_client_options) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 29
def initialize_client(args = @sqs_client_options)
  client_options = args[:client_options] || {}
  aws_access_key_id = client_options.delete(:access_key_id)
  aws_secret_access_key = client_options.delete(:secret_access_key)
  aws_profile_name = args[:aws_profile_name] || args[:aws_profile] || client_options.delete(:profile_name)
  client_options[:credentials] = (aws_access_key_id || aws_secret_access_key) ?
                                     Aws::Credentials.new(aws_access_key_id, aws_secret_access_key) :
                                     Aws::SharedCredentials.new(profile_name: aws_profile_name)
  @client = Aws::SQS::Client.new(client_options)
end
initialize_poller(args = @sqs_poller_options) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 40
def initialize_poller(args = @sqs_poller_options)
  queue_url = args.delete(:queue_url)
  args[:client] ||= @client if @client
  @poller = Aws::SQS::QueuePoller.new(queue_url, args)
end
poll(options = @sqs_poll_options, &block) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 46
def poll(options = @sqs_poll_options, &block)
  @poller.poll(options, &block)
end
symbolize_keys(value, recursive = true) click to toggle source
# File lib/envoi/restore/sqs-queue-worker.rb, line 50
def symbolize_keys (value, recursive = true)
  case value
  when Hash
    Hash[value.map { |k,v| [ k.respond_to?(:to_sym) ? k.to_sym : k, recursive ? symbolize_keys(v, true) : v ] }]
  when Array
    value.map { |v| symbolize_keys(v, recursive) }
  else
    value
  end
end