From f35128c6ed715b81ccba0139265f8010730f00d7 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 10 Dec 2024 17:01:25 +0800 Subject: [PATCH] DEV: Fix broken sidekiq logging due to eeb01ea0de56319c9c700b88995d27e16607d49f (#30199) --- app/jobs/base.rb | 2 +- spec/jobs/jobs_base_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/jobs/base.rb b/app/jobs/base.rb index fc7b3c99489..102d1e8e081 100644 --- a/app/jobs/base.rb +++ b/app/jobs/base.rb @@ -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 diff --git a/spec/jobs/jobs_base_spec.rb b/spec/jobs/jobs_base_spec.rb index a6110ac61e2..42630bf13a2 100644 --- a/spec/jobs/jobs_base_spec.rb +++ b/spec/jobs/jobs_base_spec.rb @@ -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