From 4199ada1ce341212e3d2d4890074db9de018d7a4 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 24 Jun 2022 10:28:18 +0800 Subject: [PATCH] DEV: Ensure Sidekiq logging thread is always running (#17211) --- app/jobs/base.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/jobs/base.rb b/app/jobs/base.rb index 381e5a93f8d..f1cf81974d9 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -97,14 +97,19 @@ module Jobs f.sync = true Logger.new f end + @@log_queue ||= Queue.new - @@log_thread ||= Thread.new do - begin - loop { @@logger << @@log_queue.pop } - rescue Exception => e - Discourse.warn_exception(e, message: "Sidekiq logging thread terminated unexpectedly") + + if !@@log_thread || !@@log_thead.alive? + @@log_thread = Thread.new do + loop do + @@logger << @@log_queue.pop + rescue Exception => e + Discourse.warn_exception(e, message: "Exception encountered while logging Sidekiq job") + end end end + @@log_queue.push(message) end