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 f.sync = true
Logger.new f Logger.new f
end end
@@log_queue ||= Queue.new @@log_queue ||= Queue.new
@@log_thread ||= Thread.new do
begin if !@@log_thread || !@@log_thead.alive?
loop { @@logger << @@log_queue.pop } @@log_thread = Thread.new do
rescue Exception => e loop do
Discourse.warn_exception(e, message: "Sidekiq logging thread terminated unexpectedly") @@logger << @@log_queue.pop
rescue Exception => e
Discourse.warn_exception(e, message: "Exception encountered while logging Sidekiq job")
end
end end
end end
@@log_queue.push(message) @@log_queue.push(message)
end end