Class: MailHandler::SQS::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/interfaces/sqs.rb

Overview

Yields an interface to a specific sqs queue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/interfaces/sqs.rb', line 19

def initialize(config)
  all_queues = ::AWS::SQS.new(
    access_key_id:     config[:access_key_id],
    secret_access_key: config[:secret_access_key],
    region:            config[:aws_region]
  ).queues

  @queues = config[:sqs_queues].map do |queue_name|
    all_queues.named queue_name
  end

  @batch_size = config[:batch_size] || 1
end

Instance Attribute Details

#queuesObject

Returns the value of attribute queues.



17
18
19
# File 'lib/interfaces/sqs.rb', line 17

def queues
  @queues
end

Instance Method Details

#fetch_messagesObject



33
34
35
36
37
38
39
# File 'lib/interfaces/sqs.rb', line 33

def fetch_messages
  [
    @queues.map do |queue|
      queue.receive_messages(limit: @batch_size)
    end
  ].flatten.compact
end