DEV: Further sidekiq logging stability improvements

DEV: Further sidekiq logging stability improvements

  • Open the log file in “append” mode. This avoids issues if the file does not exist (and matches standard rails log behavior)
  • Correctly parse the interval logging environment variable
diff --git a/app/jobs/base.rb b/app/jobs/base.rb
index 648cca6..aec6fd8 100644
--- a/app/jobs/base.rb
+++ b/app/jobs/base.rb
@@ -65,7 +65,11 @@ module Jobs
       end
 
       def self.raw_log(message)
-        @@logger ||= Logger.new("#{Rails.root}/log/sidekiq.log")
+        @@logger ||= begin
+          f = File.open "#{Rails.root}/log/sidekiq.log", "a"
+          f.sync = true
+          Logger.new f
+        end
         @@log_queue ||= Queue.new
         @@log_thread ||= Thread.new do
           begin
@@ -99,7 +103,7 @@ module Jobs
           begin
             loop do
               sleep interval.to_i
-              @@active_jobs.each { |j| j.write_to_log if j.current_duration > interval }
+              @@active_jobs.each { |j| j.write_to_log if j.current_duration > interval.to_i }
             end
           rescue Exception => e
             Discourse.warn_exception(e, message: "Sidekiq interval logging thread terminated unexpectedly")

GitHub sha: df474bce

2 Likes

It might be better to do the .to_i outside the loop

1 Like