diff --git a/generators/processor/templates/poller b/generators/processor/templates/poller index 2b7e3e4..5381eef 100755 --- a/generators/processor/templates/poller +++ b/generators/processor/templates/poller @@ -1,13 +1,15 @@ #!/usr/bin/env ruby + +ENV['APP_ROOT'] ||= File.expand_path(File.join(File.dirname(__FILE__), '..')) +APP_ROOT = ENV['APP_ROOT'] +script_file = File.join(APP_ROOT, 'lib', 'poller.rb') +tmp_dir = File.join(APP_ROOT, 'tmp') + require 'rubygems' require 'daemons' require 'activesupport' require 'activemessaging' -APP_ROOT = File.expand_path(File.dirname(__FILE__) + '/..') -script_file = File.join(File.dirname(__FILE__)+'/../lib/poller.rb') -tmp_dir = File.join(File.expand_path(APP_ROOT), 'tmp') - options = { :app_name => "poller", :dir_mode => :normal, diff --git a/generators/processor/templates/poller.rb b/generators/processor/templates/poller.rb index 364882e..7e6c854 100644 --- a/generators/processor/templates/poller.rb +++ b/generators/processor/templates/poller.rb @@ -4,12 +4,13 @@ STDERR.sync = true; STDERR.flush #Try to Load Merb -begin +merb_init_file = File.expand_path(File.dirname(__FILE__)+'/../config/merb_init') +if File.exists? merb_init_file require File.expand_path(File.dirname(__FILE__)+'/../config/boot') #need this because of the CWD Merb.root = MERB_ROOT - require File.expand_path(File.dirname(__FILE__)+'/../config/merb_init') -rescue LoadError + require merb_init_file +else # Load Rails RAILS_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..')) require File.join(RAILS_ROOT, 'config', 'boot') @@ -20,4 +21,4 @@ #ActiveMessaging::load_processors # Start it up! -ActiveMessaging::start \ No newline at end of file +ActiveMessaging::start diff --git a/generators/processor/templates/processor_test.rb b/generators/processor/templates/processor_test.rb index 633a9f0..0bcab52 100644 --- a/generators/processor/templates/processor_test.rb +++ b/generators/processor/templates/processor_test.rb @@ -1,5 +1,5 @@ require File.dirname(__FILE__) + '/../test_helper' -require File.dirname(__FILE__) + '/../../vendor/plugins/activemessaging/lib/activemessaging/test_helper' +require 'activemessaging/test_helper' require File.dirname(__FILE__) + '/../../app/processors/application' class <%= class_name %>ProcessorTest < Test::Unit::TestCase diff --git a/lib/activemessaging.rb b/lib/activemessaging.rb index 67bfd87..cea6342 100644 --- a/lib/activemessaging.rb +++ b/lib/activemessaging.rb @@ -1,7 +1,8 @@ module ActiveMessaging - VERSION = "0.5" #maybe this should be higher, but I'll let others judge :) + VERSION = "0.6.0" APP_ROOT = ENV['APP_ROOT'] || ENV['RAILS_ROOT'] || ((defined? RAILS_ROOT) && RAILS_ROOT) || File.dirname($0) APP_ENV = ENV['APP_ENV'] || ENV['RAILS_ENV'] || 'development' + ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) # Used to indicate that the processing for a thread shoud complete class StopProcessingException < Interrupt #:nodoc: @@ -18,9 +19,10 @@ class StopFilterException < Exception #:nodoc: end def ActiveMessaging.logger - @@logger = RAILS_DEFAULT_LOGGER if !defined?(@@logger) && (defined?(RAILS_DEFAULT_LOGGER) && !RAILS_DEFAULT_LOGGER.nil?) - @@logger = ActiveRecord::Base.logger unless defined?(@@logger) - @@logger = Logger.new(STDOUT) unless defined?(@@logger) + @@logger = nil unless defined? @@logger + @@logger ||= RAILS_DEFAULT_LOGGER if defined? RAILS_DEFAULT_LOGGER + @@logger ||= ActiveRecord::Base.logger if defined? ActiveRecord + @@logger ||= Logger.new(STDOUT) @@logger end @@ -36,18 +38,20 @@ def self.load_extensions require 'activemessaging/trace_filter' # load all under the adapters dir - Dir[APP_ROOT + '/vendor/plugins/activemessaging/lib/activemessaging/adapters/*.rb'].each{|a| + Dir[File.join(ROOT, 'lib', 'activemessaging', 'adapters', '*.rb')].each do |a| begin adapter_name = File.basename(a, ".rb") require 'activemessaging/adapters/' + adapter_name rescue RuntimeError, LoadError => e logger.debug "ActiveMessaging: adapter #{adapter_name} not loaded: #{ e.message }" end - } + end end def self.load_config + p APP_ROOT path = File.expand_path("#{APP_ROOT}/config/messaging.rb") + p path begin load path rescue MissingSourceFile @@ -115,10 +119,9 @@ class DoSomethingProcessor < ActiveMessaging::Processor #load these once to start with ActiveMessaging.load_activemessaging - - -# reload these on each request - leveraging Dispatcher semantics for consistency -begin +# reload these on each Rails request - leveraging Dispatcher semantics for consistency +if defined? Rails + ActiveMessaging.logger.info "Rails available: Adding dispatcher prepare callback." require 'dispatcher' unless defined?(::Dispatcher) # add processors and config to on_prepare if supported (rails 1.2+) @@ -127,7 +130,4 @@ class DoSomethingProcessor < ActiveMessaging::Processor ActiveMessaging.reload_activemessaging end end -rescue MissingSourceFile => e - logger.info e.message - logger.info "Rails not available." end