From 1385388452c6dc86afe0668c41e0f5a491dc193a Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 3 May 2012 00:10:27 -0300 Subject: Allow configuring a different queue consumer Also make sure to not use default queue consumer with custom queue implementation. It is up to the new queue implementation to start / shutdown the consumer. --- railties/lib/rails/application.rb | 2 +- railties/lib/rails/application/configuration.rb | 8 +++++--- railties/lib/rails/application/finisher.rb | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index c7b19c964a..c4edbae55b 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -66,7 +66,7 @@ module Rails end end - attr_accessor :assets, :sandbox + attr_accessor :assets, :sandbox, :queue_consumer alias_method :sandbox?, :sandbox attr_reader :reloaders attr_writer :queue diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 25bb680f69..a2e5dece16 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -8,10 +8,11 @@ module Rails attr_accessor :allow_concurrency, :asset_host, :asset_path, :assets, :autoflush_log, :cache_classes, :cache_store, :consider_all_requests_local, :console, :dependency_loading, :exceptions_app, :file_watcher, :filter_parameters, - :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, :preload_frameworks, - :railties_order, :relative_url_root, :secret_token, + :force_ssl, :helpers_paths, :logger, :log_formatter, :log_tags, + :preload_frameworks, :railties_order, :relative_url_root, :secret_token, :serve_static_assets, :ssl_options, :static_cache_control, :session_options, - :time_zone, :reload_classes_only_on_change, :use_schema_cache_dump, :queue + :time_zone, :reload_classes_only_on_change, :use_schema_cache_dump, + :queue, :queue_consumer attr_writer :log_level attr_reader :encoding @@ -44,6 +45,7 @@ module Rails @log_formatter = ActiveSupport::Logger::SimpleFormatter.new @use_schema_cache_dump = true @queue = Rails::Queueing::Queue + @queue_consumer = Rails::Queueing::ThreadedConsumer @assets = ActiveSupport::OrderedOptions.new @assets.enabled = false diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 6a24e01f29..84f2601f28 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -96,8 +96,8 @@ module Rails initializer :activate_queue_consumer do |app| if config.queue == Rails::Queueing::Queue - consumer = Rails::Queueing::ThreadedConsumer.start(app.queue) - at_exit { consumer.shutdown } + app.queue_consumer = config.queue_consumer.start(app.queue) + at_exit { app.queue_consumer.shutdown } end end end -- cgit v1.2.3 From 8fbf2e197f0a327ab95bc85b3d3d683e68e09cf3 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 3 May 2012 00:15:50 -0300 Subject: Allow overriding exception handling in threaded consumer --- railties/lib/rails/queueing.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb index 2e187b8555..896dd91034 100644 --- a/railties/lib/rails/queueing.rb +++ b/railties/lib/rails/queueing.rb @@ -53,7 +53,7 @@ module Rails begin job.run rescue Exception => e - Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}" + handle_exception e end end end @@ -64,6 +64,10 @@ module Rails @queue.push nil @thread.join end + + def handle_exception(e) + Rails.logger.error "Job Error: #{e.message}\n#{e.backtrace.join("\n")}" + end end end end -- cgit v1.2.3 From 7a6116b633479effe81a820d84aaf29572cc3412 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 3 May 2012 22:26:30 -0300 Subject: Add some docs and changelog entry --- railties/lib/rails/queueing.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/queueing.rb b/railties/lib/rails/queueing.rb index 896dd91034..b4bc7fcd18 100644 --- a/railties/lib/rails/queueing.rb +++ b/railties/lib/rails/queueing.rb @@ -16,13 +16,13 @@ module Rails # Jobs are run in a separate thread to catch mistakes where code # assumes that the job is run in the same thread. class TestQueue < ::Queue - # Get a list of the jobs off this queue. This method may not be + # Get a list of the jobs off this queue. This method may not be # available on production queues. def jobs @que.dup end - # Drain the queue, running all jobs in a different thread. This method + # Drain the queue, running all jobs in a different thread. This method # may not be available on production queues. def drain # run the jobs in a separate thread so assumptions of synchronous -- cgit v1.2.3