File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
lib/active_job/queue_adapters Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "delayed_job"
4
+ require "active_support/core_ext/string/inflections"
4
5
5
6
module ActiveJob
6
7
module QueueAdapters
@@ -35,12 +36,21 @@ def initialize(job_data)
35
36
end
36
37
37
38
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" ] } "
39
44
end
40
45
41
46
def perform
42
47
Base . execute ( job_data )
43
48
end
49
+
50
+ private
51
+ def log_arguments?
52
+ job_data [ "job_class" ] . constantize . log_arguments?
53
+ end
44
54
end
45
55
end
46
56
end
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments