Skip to content

Commit c50721b

Browse files
authored
Merge pull request rails#42916 from Alexander-Blair/respect-log-arguments-setting-in-application-jobs
Avoid logging delayed job arguments if log_arguments set to false
2 parents 207da35 + de28930 commit c50721b

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

activejob/lib/active_job/queue_adapters/delayed_job_adapter.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "delayed_job"
4+
require "active_support/core_ext/string/inflections"
45

56
module ActiveJob
67
module QueueAdapters
@@ -35,12 +36,21 @@ def initialize(job_data)
3536
end
3637

3738
def display_name
38-
"#{job_data['job_class']} [#{job_data['job_id']}] from DelayedJob(#{job_data['queue_name']}) with arguments: #{job_data['arguments']}"
39+
base_name = "#{job_data["job_class"]} [#{job_data["job_id"]}] from DelayedJob(#{job_data["queue_name"]})"
40+
41+
return base_name unless log_arguments?
42+
43+
"#{base_name} with arguments: #{job_data["arguments"]}"
3944
end
4045

4146
def perform
4247
Base.execute(job_data)
4348
end
49+
50+
private
51+
def log_arguments?
52+
job_data["job_class"].constantize.log_arguments?
53+
end
4454
end
4555
end
4656
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require "active_job/queue_adapters/delayed_job_adapter"
4+
5+
class DelayedJobAdapterTest < ActiveSupport::TestCase
6+
test "does not log arguments when log_arguments is set to false on a job" do
7+
job_id = SecureRandom.uuid
8+
9+
job_wrapper = ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(
10+
"job_class" => DisableLogJob.to_s,
11+
"queue_name" => "default",
12+
"job_id" => job_id,
13+
"arguments" => { "some" => { "job" => "arguments" } }
14+
)
15+
16+
assert_equal "DisableLogJob [#{job_id}] from DelayedJob(default)", job_wrapper.display_name
17+
end
18+
19+
test "logs arguments when log_arguments is set to true on a job" do
20+
job_id = SecureRandom.uuid
21+
arguments = { "some" => { "job" => "arguments" } }
22+
23+
job_wrapper = ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(
24+
"job_class" => HelloJob.to_s,
25+
"queue_name" => "default",
26+
"job_id" => job_id,
27+
"arguments" => arguments
28+
)
29+
30+
assert_equal "HelloJob [#{job_id}] from DelayedJob(default) with arguments: #{arguments}",
31+
job_wrapper.display_name
32+
end
33+
end

0 commit comments

Comments
 (0)