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:
parent
35f2a096f3
commit
411378efcf
2 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue