@@ -15,6 +15,21 @@ def self.perform
15
15
end
16
16
end
17
17
18
+ class FailedRetriableJob
19
+ extend Resque ::Plugins ::Retry
20
+
21
+ @queue = :default
22
+ @retry_limit = 3
23
+
24
+ def self . perform
25
+ 1 /0
26
+ end
27
+ end
28
+
29
+ class FailedZeroRetriesJob < FailedRetriableJob
30
+ @retry_limit = 0
31
+ end
32
+
18
33
class TaggedFailedJob
19
34
def self . perform
20
35
Sentry . set_tags ( number : 1 )
@@ -125,6 +140,74 @@ def self.perform(msg)
125
140
end
126
141
end
127
142
143
+ context "with ResqueRetry" do
144
+ context "when report_after_job_retries is true" do
145
+ before do
146
+ Sentry . configuration . resque . report_after_job_retries = true
147
+ end
148
+
149
+ it "reports exception only on the last run" do
150
+ expect do
151
+ Resque ::Job . create ( :default , FailedRetriableJob )
152
+ process_job ( worker )
153
+ end . to change { Resque ::Stat . get ( "failed" ) } . by ( 1 )
154
+ . and change { transport . events . count } . by ( 0 )
155
+
156
+ expect do
157
+ 3 . times do
158
+ process_job ( worker )
159
+ end
160
+ end . to change { transport . events . count } . by ( 1 )
161
+
162
+ event = transport . events . last . to_hash
163
+
164
+ expect ( event [ :sdk ] ) . to eq ( { name : "sentry.ruby.resque" , version : described_class ::VERSION } )
165
+ expect ( event . dig ( :exception , :values , 0 , :type ) ) . to eq ( "ZeroDivisionError" )
166
+ expect ( event [ :tags ] ) . to eq ( { "resque.queue" => "default" } )
167
+ end
168
+
169
+ it "reports exception on first run when retry_count is 0" do
170
+ expect do
171
+ Resque ::Job . create ( :default , FailedZeroRetriesJob )
172
+ process_job ( worker )
173
+ end . to change { Resque ::Stat . get ( "failed" ) } . by ( 1 )
174
+ . and change { transport . events . count } . by ( 1 )
175
+
176
+ event = transport . events . last . to_hash
177
+
178
+ expect ( event [ :sdk ] ) . to eq ( { name : "sentry.ruby.resque" , version : described_class ::VERSION } )
179
+ expect ( event . dig ( :exception , :values , 0 , :type ) ) . to eq ( "ZeroDivisionError" )
180
+ expect ( event [ :tags ] ) . to eq ( { "resque.queue" => "default" } )
181
+ end
182
+ end
183
+
184
+ context "when report_after_job_retries is false" do
185
+ before do
186
+ Sentry . configuration . resque . report_after_job_retries = false
187
+ end
188
+
189
+ it "reports exeception all the runs" do
190
+ expect do
191
+ Resque ::Job . create ( :default , FailedRetriableJob )
192
+ process_job ( worker )
193
+ end . to change { Resque ::Stat . get ( "failed" ) } . by ( 1 )
194
+ . and change { transport . events . count } . by ( 1 )
195
+
196
+ expect do
197
+ 3 . times do
198
+ process_job ( worker )
199
+ end
200
+ end . to change { transport . events . count } . by ( 3 )
201
+
202
+ event = transport . events . last . to_hash
203
+
204
+ expect ( event [ :sdk ] ) . to eq ( { name : "sentry.ruby.resque" , version : described_class ::VERSION } )
205
+ expect ( event . dig ( :exception , :values , 0 , :type ) ) . to eq ( "ZeroDivisionError" )
206
+ expect ( event [ :tags ] ) . to eq ( { "resque.queue" => "default" } )
207
+ end
208
+ end
209
+ end
210
+
128
211
context "with ActiveJob" do
129
212
require "rails"
130
213
require "active_job"
0 commit comments