DEV: Ensure Sidekiq logging thread is always running (#17211)

This commit is contained in:
Alan Guo Xiang Tan 2022-06-24 10:28:18 +08:00 committed by GitHub
parent d1d6868325
commit 4199ada1ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 5 deletions

View File

@ -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