Class: SQSPoller::SQSPoller

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SQSPoller

Returns a new instance of SQSPoller.



21
22
23
24
25
26
27
28
# File 'lib/sqspoller.rb', line 21

def initialize(options={})
  options[:config] ||= Util.config_files
  @config = Config.load(options[:config])
  Config.load_handlers
  @queues ||= @config['sqspoller']['queues'].keys
  AWS.config(@config['aws'])
  @sqs = AWS::SQS.new
end

Instance Attribute Details

#confObject

Returns the value of attribute conf.



12
13
14
# File 'lib/sqspoller.rb', line 12

def conf
  @conf
end

#queueObject

Returns the value of attribute queue.



12
13
14
# File 'lib/sqspoller.rb', line 12

def queue
  @queue
end

#sqsObject

Returns the value of attribute sqs.



12
13
14
# File 'lib/sqspoller.rb', line 12

def sqs
  @sqs
end

Class Method Details

.debug(msg) ⇒ Object



18
# File 'lib/sqspoller.rb', line 18

def debug(msg); @logger.debug(msg); end

.info(msg) ⇒ Object



16
# File 'lib/sqspoller.rb', line 16

def info(msg); @logger.info(msg); end

.warn(msg) ⇒ Object



17
# File 'lib/sqspoller.rb', line 17

def warn(msg); @logger.warn(msg); end

Instance Method Details

#poll_queuesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sqspoller.rb', line 30

def poll_queues
  threads = []

  for queue_short_name in @queues
    poll_config = Config['sqspoller']['queues'][queue_short_name]
    SQSPoller.info("Initiated polling of queue '#{queue_short_name}'")
    queue_url = @sqs.queues.named(queue_short_name)
    threads << Thread.new(queue_short_name) { |queue_name|
      queue_url.poll(poll_config) { |msg| yield(queue_name, msg) }
    }
  end

  threads.each { |aThread|  aThread.join }
end

#process(queue_name, msg) ⇒ Object



45
46
47
# File 'lib/sqspoller.rb', line 45

def process(queue_name, msg)
  Handler.process(queue_name, msg)
end