Sha256: 51f65957cf9421440043e8b44ee359b6561e8a1688eaa61b8718719aa21be068

Contents?: true

Size: 945 Bytes

Versions: 11

Compression:

Stored size: 945 Bytes

Contents

require 'aws-sdk'
require 'alephant/logger'

module Alephant
  module Publisher
    class Queue
      WAIT_TIME = 5
      VISABILITY_TIMEOUT = 300

      include ::Alephant::Logger

      attr_reader :timeout, :wait_time
      attr_accessor :q

      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

      def sleep_until_queue_exists
        sleep 1 until @q.exists?
      end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
alephant-publisher-0.2.5 lib/alephant/publisher/queue.rb
alephant-publisher-0.2.4 lib/alephant/publisher/queue.rb
alephant-publisher-0.2.3 lib/alephant/publisher/queue.rb
alephant-publisher-0.2.2 lib/alephant/publisher/queue.rb
alephant-publisher-0.2.1 lib/alephant/publisher/queue.rb
alephant-publisher-0.2.0 lib/alephant/publisher/queue.rb
alephant-publisher-0.1.8 lib/alephant/publisher/queue.rb
alephant-publisher-0.1.7 lib/alephant/publisher/queue.rb
alephant-publisher-0.1.6 lib/alephant/publisher/queue.rb
alephant-publisher-0.1.5 lib/alephant/publisher/queue.rb
alephant-publisher-0.1.4 lib/alephant/publisher/queue.rb