From be70d6e2806edc7c5becee1f27035ebf5fc9ea8b Mon Sep 17 00:00:00 2001 From: "W. Andrew Loe III" Date: Mon, 3 Jun 2013 11:32:49 -0700 Subject: [PATCH 1/2] Load poller correctly via rake task in Rails 3. --- lib/tasks/start_consumers.rake | 4 ++-- poller.rb | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/tasks/start_consumers.rake b/lib/tasks/start_consumers.rake index 5ec1946..054b129 100644 --- a/lib/tasks/start_consumers.rake +++ b/lib/tasks/start_consumers.rake @@ -2,7 +2,7 @@ namespace "activemessaging" do desc 'Run all consumers' task :start_consumers do - load File.dirname(__FILE__) + '/../poller.rb' + load File.join(File.dirname(__FILE__), '..', '..', 'poller.rb') end -end \ No newline at end of file +end diff --git a/poller.rb b/poller.rb index f11fac6..c2eb12d 100644 --- a/poller.rb +++ b/poller.rb @@ -3,12 +3,8 @@ STDOUT.sync = true; STDOUT.flush STDERR.sync = true; STDERR.flush -# Load Rails -RAILS_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..','..','..')) -load File.join(RAILS_ROOT, 'config', 'environment.rb') +load File.join(Rails.root, 'config', 'environment.rb') -# Load ActiveMessaging processors -#ActiveMessaging::load_processors # Start it up! ActiveMessaging::start From 41c9605da8809f924bea7a898eda3ae7fbc991cc Mon Sep 17 00:00:00 2001 From: "W. Andrew Loe III" Date: Mon, 3 Jun 2013 14:40:10 -0700 Subject: [PATCH 2/2] Use an environment variable to set the process group. --- lib/activemessaging/gateway.rb | 30 +++++++++++++----------------- poller.rb | 1 - 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/activemessaging/gateway.rb b/lib/activemessaging/gateway.rb index e7059f6..3411099 100644 --- a/lib/activemessaging/gateway.rb +++ b/lib/activemessaging/gateway.rb @@ -342,24 +342,20 @@ def processor_group group_name, *processors end def current_processor_group - if ARGV.length > 0 && !@current_processor_group - ARGV.each {|arg| - pair = arg.split('=') - if pair[0] == 'process-group' - group_sym = pair[1].to_sym - if processor_groups.has_key? group_sym - @current_processor_group = group_sym - else - ActiveMessaging.logger.error "Unrecognized process-group." - ActiveMessaging.logger.error "You specified process-group #{pair[1]}, make sure this is specified in config/messaging.rb" - ActiveMessaging.logger.error " ActiveMessaging::Gateway.define do |s|" - ActiveMessaging.logger.error " s.processor_groups = { :group1 => [:foo_bar1_processor], :group2 => [:foo_bar2_processor] }" - ActiveMessaging.logger.error " end" - exit - end - end - } + if ENV['PROCESS_GROUP'].present? && !@current_processor_group + group_sym = ENV['PROCESS_GROUP'].to_sym + if processor_groups.has_key? group_sym + @current_processor_group = group_sym + else + ActiveMessaging.logger.error "Unrecognized process-group." + ActiveMessaging.logger.error "You specified process-group #{pair[1]}, make sure this is specified in config/messaging.rb" + ActiveMessaging.logger.error " ActiveMessaging::Gateway.define do |s|" + ActiveMessaging.logger.error " s.processor_groups = { :group1 => [:foo_bar1_processor], :group2 => [:foo_bar2_processor] }" + ActiveMessaging.logger.error " end" + exit + end end + @current_processor_group end diff --git a/poller.rb b/poller.rb index c2eb12d..59c326e 100644 --- a/poller.rb +++ b/poller.rb @@ -5,6 +5,5 @@ load File.join(Rails.root, 'config', 'environment.rb') - # Start it up! ActiveMessaging::start