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

Job worker thread logs to stderr if no logger is provided

This commit is contained in:
Jeremy Kemper 2012-10-26 11:28:51 -07:00
parent 35f2a096f3
commit 411378efcf
2 changed files with 13 additions and 2 deletions

View file

@ -66,7 +66,7 @@ module ActiveSupport
class ThreadedQueueConsumer
def initialize(queue, options = {})
@queue = queue
@logger = options[:logger]
@logger = options[:logger] || Logger.new($stderr)
end
def start
@ -96,7 +96,6 @@ module ActiveSupport
end
def handle_exception(job, exception)
raise exception unless @logger
@logger.error "Job Error: #{exception.message}\n#{exception.backtrace.join("\n")}"
end
end

View file

@ -71,6 +71,18 @@ class TestThreadConsumer < ActiveSupport::TestCase
assert_match 'Job Error: RuntimeError: Error!', @logger.logged(:error).last
end
test "logger defaults to stderr" do
begin
$stderr, old_stderr = StringIO.new, $stderr
queue = ActiveSupport::Queue.new
queue.push Job.new { raise "RuntimeError: Error!" }
queue.drain
assert_match 'Job Error', $stderr.string
ensure
$stderr = old_stderr
end
end
test "test overriding exception handling" do
@queue.consumer.instance_eval do
def handle_exception(job, exception)