Class: SqsBunny
- Inherits:
-
Object
- Object
- SqsBunny
- Defined in:
- lib/sqs_bunny.rb
Overview
Main execution class, just call SqsBunny.run
and pass in the path of your configuration file
Defined Under Namespace
Classes: NullLogger
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.run(config_file_path, logger = nil) ⇒ Object
Run this method to start the job, optionally pass in a configuration hash.
Instance Method Summary collapse
- #go ⇒ Object
-
#initialize(config) ⇒ SqsBunny
constructor
A new instance of SqsBunny.
-
#keep_polling? ⇒ Boolean
This method can be overidden to provide your own polling stop semantics.
- #send_message(client, message) ⇒ Object
Constructor Details
#initialize(config) ⇒ SqsBunny
Returns a new instance of SqsBunny.
20 21 22 23 |
# File 'lib/sqs_bunny.rb', line 20 def initialize config @config = {'wait_time_seconds'=>10}.merge config @poll_count = 0 end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/sqs_bunny.rb', line 9 def logger @logger end |
Class Method Details
.run(config_file_path, logger = nil) ⇒ Object
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
13 14 15 16 17 18 |
# 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 |
Instance Method Details
#go ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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.(queue_url:parent_url,wait_time_seconds:@config['wait_time_seconds']) if resp.respond_to? :messages resp..each do |x| log.info x.body client, x client.(queue_url:parent_url,receipt_handle:x.receipt_handle) end else log.debug "No messages" end break unless keep_polling? end end |
#keep_polling? ⇒ Boolean
This method can be overidden to provide your own polling stop semantics
53 54 55 |
# File 'lib/sqs_bunny.rb', line 53 def keep_polling? @config['poll_max'].nil? || @poll_count < @config['poll_max'] end |
#send_message(client, message) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/sqs_bunny.rb', line 45 def client, return unless @config['children'] @config['children'].each do |child| client.(queue_url:child['queue_url'],message_body:.body) end end |