Class: QProcessor::SQSSource

Inherits:
Object
  • Object
show all
Defined in:
lib/qprocessor/sqs_source.rb

Constant Summary collapse

MAX_MESSAGE_WAIT =

A constant for the maximum wait for message timeout to be used by the source.

3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSQSSource

Returns a new instance of SQSSource.



12
13
14
# File 'lib/qprocessor/sqs_source.rb', line 12

def initialize
  @name = "SQS Source"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/qprocessor/sqs_source.rb', line 15

def name
  @name
end

Instance Method Details

#get {|message| ... } ⇒ Object

This method blocks until a job is available, at which points it is returned.

Yields:

  • (message)


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

def get
  message = nil
  client  = sqs_client
  url     = sqs_queue_url(sqs_queue_name)
  while message.nil?
    result  = client.receive_message(max_number_of_messages: 1,
                                     queue_url:              url,
                                     wait_time_seconds:      MAX_MESSAGE_WAIT)
    message = QProcessor::SQSMessage.new(result.messages[0], client, url) if !result.messages.empty?
  end
  yield message if block_given?
  message
end