@@ -49,18 +49,12 @@ def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: ni
49
49
if executions < attempts
50
50
retry_job wait : determine_delay ( wait ) , queue : queue , priority : priority , error : error
51
51
else
52
- payload = {
53
- job : self ,
54
- adapter : self . class . queue_adapter ,
55
- error : error
56
- }
57
-
58
52
if block_given?
59
- ActiveSupport :: Notifications . instrument ( " retry_stopped.active_job" , payload ) do
53
+ instrument : retry_stopped, error : error do
60
54
yield self , error
61
55
end
62
56
else
63
- ActiveSupport :: Notifications . instrument ( " retry_stopped.active_job" , payload )
57
+ instrument : retry_stopped, error : error
64
58
raise error
65
59
end
66
60
end
@@ -87,16 +81,8 @@ def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: ni
87
81
# end
88
82
def discard_on ( *exceptions )
89
83
rescue_from ( *exceptions ) do |error |
90
- payload = {
91
- job : self ,
92
- adapter : self . class . queue_adapter ,
93
- error : error
94
- }
95
-
96
- ActiveSupport ::Notifications . instrument ( "discard.active_job" , payload ) do
97
- if block_given?
98
- yield self , error
99
- end
84
+ instrument :discard , error : error do
85
+ yield self , error if block_given?
100
86
end
101
87
end
102
88
end
@@ -124,14 +110,7 @@ def discard_on(*exceptions)
124
110
# end
125
111
# end
126
112
def retry_job ( options = { } )
127
- payload = {
128
- job : self ,
129
- adapter : self . class . queue_adapter ,
130
- error : options [ :error ] ,
131
- wait : options [ :wait ]
132
- }
133
-
134
- ActiveSupport ::Notifications . instrument ( "enqueue_retry.active_job" , payload ) do
113
+ instrument :enqueue_retry , options . slice ( :error , :wait ) do
135
114
enqueue options
136
115
end
137
116
end
@@ -154,5 +133,11 @@ def determine_delay(seconds_or_duration_or_algorithm)
154
133
raise "Couldn't determine a delay based on #{ seconds_or_duration_or_algorithm . inspect } "
155
134
end
156
135
end
136
+
137
+ def instrument ( name , error : nil , wait : nil , &block )
138
+ payload = { job : self , adapter : self . class . queue_adapter , error : error , wait : wait }
139
+
140
+ ActiveSupport ::Notifications . instrument ( "#{ name } .active_job" , payload , &block )
141
+ end
157
142
end
158
143
end
0 commit comments