Class: Alephant::Publisher::Queue

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/publisher/queue.rb

Constant Summary collapse

WAIT_TIME =
5
VISABILITY_TIMEOUT =
300

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, timeout = VISABILITY_TIMEOUT, wait_time = WAIT_TIME) ⇒ Queue

Returns a new instance of Queue.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/alephant/publisher/queue.rb', line 15

def initialize(id, timeout = VISABILITY_TIMEOUT, wait_time = WAIT_TIME)
  @timeout = timeout
  @wait_time = wait_time
  @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.



13
14
15
# File 'lib/alephant/publisher/queue.rb', line 13

def q
  @q
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



12
13
14
# File 'lib/alephant/publisher/queue.rb', line 12

def timeout
  @timeout
end

#wait_timeObject (readonly)

Returns the value of attribute wait_time.



12
13
14
# File 'lib/alephant/publisher/queue.rb', line 12

def wait_time
  @wait_time
end

Instance Method Details

#messageObject



34
35
36
37
38
39
# File 'lib/alephant/publisher/queue.rb', line 34

def message
  @q.receive_message({
    :visibility_timeout => @timeout,
    :wait_time_seconds => @wait_time
  })
end

#sleep_until_queue_existsObject



30
31
32
# File 'lib/alephant/publisher/queue.rb', line 30

def sleep_until_queue_exists
  sleep 1 until @q.exists?
end