Class: Envoi::Restore::SQSQueueWorker
- Inherits:
-
Object
- Object
- Envoi::Restore::SQSQueueWorker
- Defined in:
- lib/envoi/restore/sqs-queue-worker.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#poller ⇒ Object
readonly
Returns the value of attribute poller.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ SQSQueueWorker
constructor
A new instance of SQSQueueWorker.
- #initialize_client(args = @sqs_client_options) ⇒ Object
- #initialize_poller(args = @sqs_poller_options) ⇒ Object
- #poll(options = @sqs_poll_options, &block) ⇒ Object
- #symbolize_keys(value, recursive = true) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ SQSQueueWorker
Returns a new instance of SQSQueueWorker.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 7 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 7 def config @config end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 7 def logger @logger end |
#poller ⇒ Object (readonly)
Returns the value of attribute poller.
7 8 9 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 7 def poller @poller end |
Class Method Details
.poll(args, &block) ⇒ Object
61 62 63 64 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 61 def self.poll(args, &block) handler = self.new(args) handler.poll(&block) end |
Instance Method Details
#initialize_client(args = @sqs_client_options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 29 def initialize_client(args = @sqs_client_options) = args[:client_options] || {} aws_access_key_id = .delete(:access_key_id) aws_secret_access_key = .delete(:secret_access_key) aws_profile_name = args[:aws_profile_name] || args[:aws_profile] || .delete(:profile_name) [: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() end |
#initialize_poller(args = @sqs_poller_options) ⇒ Object
40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 |
# File 'lib/envoi/restore/sqs-queue-worker.rb', line 46 def poll( = @sqs_poll_options, &block) @poller.poll(, &block) end |
#symbolize_keys(value, recursive = true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# 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 |