class SqsBunny
Main execution class, just call SqsBunny.run
and pass in the path of your configuration file
Attributes
logger[RW]
Public Class Methods
new(config)
click to toggle source
# File lib/sqs_bunny.rb, line 20 def initialize config @config = {'wait_time_seconds'=>10}.merge config @poll_count = 0 end
run(config_file_path, logger=nil)
click to toggle source
Run this method to start the job, optionally pass in a configuration hash. Otherwise the job will look for a JSON configuration at config/setup.json
# File lib/sqs_bunny.rb, line 13 def self.run config_file_path, logger=nil raise "Configuration file could not be found at #{config_file_path}" unless File.exists? config_file_path s = self.new(JSON.parse(IO.read(config_file_path))) s.logger = logger s.go end
Public Instance Methods
go()
click to toggle source
# File lib/sqs_bunny.rb, line 25 def go while true @poll_count += 1 client = Aws::SQS::Client.new parent_url = @config['parent_q']['queue_url'] log.debug "Polling for messages at #{parent_url}" resp = client.receive_message(queue_url:parent_url,wait_time_seconds:@config['wait_time_seconds']) if resp.respond_to? :messages resp.messages.each do |x| log.info x.body send_message client, x client.delete_message(queue_url:parent_url,receipt_handle:x.receipt_handle) end else log.debug "No messages" end break unless keep_polling? end end
keep_polling?()
click to toggle source
This method can be overidden to provide your own polling stop semantics
# File lib/sqs_bunny.rb, line 53 def keep_polling? @config['poll_max'].nil? || @poll_count < @config['poll_max'] end
send_message(client, message)
click to toggle source
# File lib/sqs_bunny.rb, line 45 def send_message client, message return unless @config['children'] @config['children'].each do |child| client.send_message(queue_url:child['queue_url'],message_body:message.body) end end
Private Instance Methods
log()
click to toggle source
# File lib/sqs_bunny.rb, line 66 def log @logger ||= NullLogger.new end