Class: Barbeque::MessageQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/barbeque/message_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_queue) ⇒ MessageQueue

Returns a new instance of MessageQueue.



9
10
11
12
13
# File 'lib/barbeque/message_queue.rb', line 9

def initialize(job_queue)
  @job_queue = job_queue
  @messages  = []
  @stop      = false
end

Instance Attribute Details

#job_queueObject (readonly)

Returns the value of attribute job_queue.



7
8
9
# File 'lib/barbeque/message_queue.rb', line 7

def job_queue
  @job_queue
end

Instance Method Details

#delete_message(message) ⇒ Object

Remove a message from SQS queue.

Parameters:



33
34
35
36
37
38
# File 'lib/barbeque/message_queue.rb', line 33

def delete_message(message)
  client.delete_message(
    queue_url: @job_queue.queue_url,
    receipt_handle: message.receipt_handle,
  )
end

#dequeueBarbeque::Message::Base

Receive a message from SQS queue.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/barbeque/message_queue.rb', line 17

def dequeue
  loop do
    return nil if @stop
    message = receive_message
    if message
      if message.valid?
        return message
      else
        delete_message(message)
      end
    end
  end
end

#stop!Object



40
41
42
# File 'lib/barbeque/message_queue.rb', line 40

def stop!
  @stop = true
end