Class: Alephant::Queue

Inherits:
Object
  • Object
show all
Includes:
Logger
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.



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

def initialize(id)
  @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.



8
9
10
# File 'lib/alephant/models/queue.rb', line 8

def q
  @q
end

Instance Method Details

#poll(*args, &block) ⇒ Object



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

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

#sleep_until_queue_existsObject



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

def sleep_until_queue_exists
  sleep 1 until @q.exists?
end