From 36f8697a59e637758759b03d63667ab4b0fe2bf0 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 11 Oct 2017 17:19:26 +0800 Subject: [PATCH] FIX: Exception has to be wrapped in the connection as well. --- lib/scheduler/defer.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/scheduler/defer.rb b/lib/scheduler/defer.rb index 8e3511f824d..b21bc3c5f66 100644 --- a/lib/scheduler/defer.rb +++ b/lib/scheduler/defer.rb @@ -63,17 +63,14 @@ module Scheduler # using non_block to match Ruby #deq def do_work(non_block = false) db, job, desc = @queue.deq(non_block) + db ||= RailsMultisite::ConnectionManagement::DEFAULT - begin - if db - RailsMultisite::ConnectionManagement.with_connection(db: db) do - job.call - end - else + RailsMultisite::ConnectionManagement.with_connection(db: db) do + begin job.call + rescue => ex + Discourse.handle_job_exception(ex, message: "Running deferred code '#{desc}'") end - rescue => ex - Discourse.handle_job_exception(ex, message: "Running deferred code '#{desc}'") end rescue => ex Discourse.handle_job_exception(ex, message: "Processing deferred code queue")