BUGFIX: handle partial job failure in multisite

log all failures
This commit is contained in:
Sam Saffron 2014-02-21 15:31:15 +11:00
parent 2ab76f60d1
commit 9a3af8997b
2 changed files with 28 additions and 1 deletions

View file

@ -101,6 +101,7 @@ module Jobs
end
total_db_time = 0
exceptions = []
dbs.each do |db|
begin
thread_exception = nil
@ -137,10 +138,17 @@ module Jobs
end
t.join
raise thread_exception if thread_exception
exceptions << thread_exception
end
end
if exceptions.length > 0
exceptions[1..-1].each do |exception|
Discourse.handle_exception(exception, opts)
end
raise exceptions[0]
end
ensure
ActiveRecord::Base.connection_handler.clear_active_connections!
@db_duration = total_db_time

View file

@ -2,6 +2,25 @@ require 'spec_helper'
require_dependency 'jobs/base'
describe Jobs::Base do
class BadJob < Jobs::Base
attr_accessor :fail_count
def execute(args)
@fail_count ||= 0
@fail_count += 1
raise StandardError
end
end
it 'handles errors in multisite' do
RailsMultisite::ConnectionManagement.expects(:all_dbs).returns(['default','default'])
# just stub so logs are not noisy
Discourse.expects(:handle_exception).returns(nil)
bad = BadJob.new
expect{bad.perform({})}.to raise_error
bad.fail_count.should == 2
end
it 'delegates the process call to execute' do
Jobs::Base.any_instance.expects(:execute).with('hello' => 'world')