Class: Alephant::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/alephant/models/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Queue

Returns a new instance of Queue.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/alephant/models/queue.rb', line 7

def initialize(id)
  @logger = ::Alephant.logger

  @sqs = AWS::SQS.new
  @q = @sqs.queues[id]

  unless @q.exists?
    @q = @sqs.queues.create(id)
    sleep_until_queue_exists
    @logger.info("Queue.initialize: created queue with id #{id}")
  end

  @logger.info("Queue.initialize: ended with id #{id}")
end

Instance Attribute Details

#qObject

Returns the value of attribute q.



5
6
7
# File 'lib/alephant/models/queue.rb', line 5

def q
  @q
end

Instance Method Details

#poll(*args, &block) ⇒ Object



26
27
28
29
# File 'lib/alephant/models/queue.rb', line 26

def poll(*args, &block)
  @logger.info("Queue.poll: polling with arguments #{args}")
  @q.poll(*args, &block)
end

#sleep_until_queue_existsObject



22
23
24
# File 'lib/alephant/models/queue.rb', line 22

def sleep_until_queue_exists
  sleep 1 until @q.exists?
end