FIX: Exception has to be wrapped in the connection as well.

This commit is contained in:
Guo Xiang Tan 2017-10-11 17:19:26 +08:00
parent 09721090a3
commit 36f8697a59
1 changed files with 5 additions and 8 deletions

View File

@ -63,17 +63,14 @@ module Scheduler
# using non_block to match Ruby #deq # using non_block to match Ruby #deq
def do_work(non_block = false) def do_work(non_block = false)
db, job, desc = @queue.deq(non_block) db, job, desc = @queue.deq(non_block)
db ||= RailsMultisite::ConnectionManagement::DEFAULT
begin RailsMultisite::ConnectionManagement.with_connection(db: db) do
if db begin
RailsMultisite::ConnectionManagement.with_connection(db: db) do
job.call
end
else
job.call job.call
rescue => ex
Discourse.handle_job_exception(ex, message: "Running deferred code '#{desc}'")
end end
rescue => ex
Discourse.handle_job_exception(ex, message: "Running deferred code '#{desc}'")
end end
rescue => ex rescue => ex
Discourse.handle_job_exception(ex, message: "Processing deferred code queue") Discourse.handle_job_exception(ex, message: "Processing deferred code queue")