1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Job consumer logs to Rails.logger by default

This commit is contained in:
Jeremy Kemper 2012-10-26 16:18:39 -07:00
parent 26f52b2ac1
commit bf2009f995
3 changed files with 7 additions and 2 deletions

View file

@ -64,9 +64,12 @@ module ActiveSupport
# queue and joins the thread, which will ensure that all jobs
# are executed before the process finally dies.
class ThreadedQueueConsumer
attr_accessor :logger
def initialize(queue, options = {})
@queue = queue
@logger = options[:logger] || Logger.new($stderr)
@logger = options[:logger]
@fallback_logger = Logger.new($stderr)
end
def start
@ -96,7 +99,7 @@ module ActiveSupport
end
def handle_exception(job, exception)
@logger.error "Job Error: #{job.inspect}\n#{exception.message}\n#{exception.backtrace.join("\n")}"
(logger || @fallback_logger).error "Job Error: #{job.inspect}\n#{exception.message}\n#{exception.backtrace.join("\n")}"
end
end
end

View file

@ -99,6 +99,7 @@ module Rails
initializer :activate_queue_consumer do |app|
if config.queue.class == ActiveSupport::Queue
app.queue_consumer = config.queue_consumer || config.queue.consumer
app.queue_consumer.logger ||= Rails.logger if app.queue_consumer.respond_to?(:logger=)
app.queue_consumer.start
at_exit { app.queue_consumer.shutdown }
end

View file

@ -78,6 +78,7 @@ module ApplicationTests
assert_nil Rails.application.config.queue_consumer
assert_kind_of ActiveSupport::ThreadedQueueConsumer, Rails.application.queue_consumer
assert_equal Rails.logger, Rails.application.queue_consumer.logger
end
test "attempting to marshal a queue will raise an exception" do