mirror of
https://github.com/discourse/discourse.git
synced 2025-04-09 17:02:56 +08:00
BUGFIX: handle partial job failure in multisite
log all failures
This commit is contained in:
parent
2ab76f60d1
commit
9a3af8997b
@ -101,6 +101,7 @@ module Jobs
|
|||||||
end
|
end
|
||||||
|
|
||||||
total_db_time = 0
|
total_db_time = 0
|
||||||
|
exceptions = []
|
||||||
dbs.each do |db|
|
dbs.each do |db|
|
||||||
begin
|
begin
|
||||||
thread_exception = nil
|
thread_exception = nil
|
||||||
@ -137,10 +138,17 @@ module Jobs
|
|||||||
end
|
end
|
||||||
t.join
|
t.join
|
||||||
|
|
||||||
raise thread_exception if thread_exception
|
exceptions << thread_exception
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if exceptions.length > 0
|
||||||
|
exceptions[1..-1].each do |exception|
|
||||||
|
Discourse.handle_exception(exception, opts)
|
||||||
|
end
|
||||||
|
raise exceptions[0]
|
||||||
|
end
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
ActiveRecord::Base.connection_handler.clear_active_connections!
|
ActiveRecord::Base.connection_handler.clear_active_connections!
|
||||||
@db_duration = total_db_time
|
@db_duration = total_db_time
|
||||||
|
@ -2,6 +2,25 @@ require 'spec_helper'
|
|||||||
require_dependency 'jobs/base'
|
require_dependency 'jobs/base'
|
||||||
|
|
||||||
describe Jobs::Base do
|
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
|
it 'delegates the process call to execute' do
|
||||||
Jobs::Base.any_instance.expects(:execute).with('hello' => 'world')
|
Jobs::Base.any_instance.expects(:execute).with('hello' => 'world')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user