Class: SQSPoller::SQSPoller
- Inherits:
-
Object
- Object
- SQSPoller::SQSPoller
- Defined in:
- lib/sqspoller.rb
Instance Attribute Summary collapse
-
#conf ⇒ Object
Returns the value of attribute conf.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#sqs ⇒ Object
Returns the value of attribute sqs.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ SQSPoller
constructor
A new instance of SQSPoller.
- #poll_queues ⇒ Object
- #process(queue_name, msg) ⇒ Object
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(={}) [:config] ||= Util.config_files @config = Config.load([:config]) Config.load_handlers @queues ||= @config['sqspoller']['queues'].keys AWS.config(@config['aws']) @sqs = AWS::SQS.new end |
Instance Attribute Details
#conf ⇒ Object
Returns the value of attribute conf.
12 13 14 |
# File 'lib/sqspoller.rb', line 12 def conf @conf end |
#queue ⇒ Object
Returns the value of attribute queue.
12 13 14 |
# File 'lib/sqspoller.rb', line 12 def queue @queue end |
#sqs ⇒ Object
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_queues ⇒ Object
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 |