DEV: Fix broken sidekiq logging due to eeb01ea0de (#30199)

This commit is contained in:
Alan Guo Xiang Tan 2024-12-10 17:01:25 +08:00 committed by GitHub
parent 58e3e0cc4f
commit f35128c6ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 5 deletions

View File

@ -130,7 +130,7 @@ module Jobs
def self.logger
@@logger ||=
begin
File.touch(log_path) if !File.exist?(log_path)
FileUtils.touch(log_path) if !File.exist?(log_path)
Logger.new(log_path)
end
end

View File

@ -150,24 +150,24 @@ RSpec.describe ::Jobs::Base do
end
context "when `Discourse.enable_sidekiq_logging?` is `true`" do
let(:tmp_log_file) { Tempfile.new("sidekiq.log") }
let(:tmp_log_file_path) { "#{Rails.root}/tmp/sidekiq_test_log.log" }
before do
Discourse.enable_sidekiq_logging
described_class::JobInstrumenter.set_log_path(tmp_log_file.path)
described_class::JobInstrumenter.set_log_path(tmp_log_file_path)
end
after do
Discourse.disable_sidekiq_logging
described_class::JobInstrumenter.reset_log_path
tmp_log_file.close
FileUtils.rm(tmp_log_file_path)
end
it "should log the job in the sidekiq log file" do
job = GoodJob.new
job.perform({ some_param: "some_value" })
parsed_logline = JSON.parse(File.read(tmp_log_file.path).split("\n").first)
parsed_logline = JSON.parse(File.read(tmp_log_file_path).split("\n").first)
expect(parsed_logline["hostname"]).to be_present
expect(parsed_logline["pid"]).to be_present