resque-retry 1.5.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +24 -0
- data/.gitignore +2 -0
- data/HISTORY.md +115 -21
- data/README.md +158 -21
- data/lib/resque/failure/multiple_with_retry_suppression.rb +77 -24
- data/lib/resque/plugins/exponential_backoff.rb +10 -5
- data/lib/resque/plugins/retry.rb +93 -24
- data/lib/resque-retry/server.rb +13 -5
- data/lib/resque-retry/version.rb +1 -1
- data/resque-retry.gemspec +3 -4
- data/test/exponential_backoff_test.rb +7 -0
- data/test/ignore_exceptions_test.rb +26 -0
- data/test/multiple_failure_test.rb +41 -8
- data/test/resque_inline_test.rb +23 -0
- data/test/resque_test.rb +18 -4
- data/test/retry_custom_delay_test.rb +23 -0
- data/test/retry_exception_delay_test.rb +9 -1
- data/test/retry_queue_test.rb +25 -0
- data/test/retry_test.rb +23 -27
- data/test/test_helper.rb +31 -25
- data/test/test_jobs.rb +103 -13
- metadata +29 -15
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e59965fb9d40a6d3f680291e5cbdec8edf04946ad50749175e984062a52e9d1c
|
4
|
+
data.tar.gz: c7962de9928657b3b4b2745efbb5e403a512f44a1b0cd5db5701aee87302dffa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c214710cdfb36737e8ed9cc598f625df4020e29a056f235fd8aa636cec7f2e220f63afbfa29090b944444cee0f938b66d676b23496671b65f7f1051f08b8e4
|
7
|
+
data.tar.gz: c78705b7a1a87c9b92c8eb6c9b72070dfb51f52dcab7b3cdc55e2a0a89940f34a1ef98255f11986a43011c6a56abeeee0d2f96493b41ee921ad90dab178ce76b
|
@@ -0,0 +1,24 @@
|
|
1
|
+
on: [push, pull_request]
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
test:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
services:
|
7
|
+
redis:
|
8
|
+
image: redis
|
9
|
+
ports:
|
10
|
+
- 6379:6379
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby-version: ['3.1', '3.0', '2.7']
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
- name: Install dependencies
|
22
|
+
run: bundle install
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/HISTORY.md
CHANGED
@@ -1,4 +1,80 @@
|
|
1
|
-
|
1
|
+
# 1.8.0 (2023-04-15)
|
2
|
+
|
3
|
+
* Address `retry_key_exists?` issue that was originally reported /
|
4
|
+
partially addressed here:
|
5
|
+
https://github.com/lantins/resque-retry/pull/173
|
6
|
+
* Fix test-failures due to API / interface changes for dependencies
|
7
|
+
* Remove `ruby@2.6` from the test[ing] matrix as it has been EOL for
|
8
|
+
quite some time at this point (as of this PR `ruby@2.7` is also EOL,
|
9
|
+
but I left this in for the time being)
|
10
|
+
* Add `ruby@3.1` to the test[ing] matrix
|
11
|
+
|
12
|
+
# 1.7.6 (2021-08-06)
|
13
|
+
|
14
|
+
* Fix Redis 4.3 breaking saving job failures with multiple failure backend
|
15
|
+
* Disable verbose logging by default during test-runs
|
16
|
+
* Remove support for ruby < 2.6
|
17
|
+
|
18
|
+
# 1.7.5 (2021-08-06)
|
19
|
+
|
20
|
+
* Support `retry_delay` methods with different arity
|
21
|
+
* Switch over to _GitHub_ CI for PR test-execution
|
22
|
+
|
23
|
+
# 1.7.4 (2020-10-09)
|
24
|
+
|
25
|
+
* Rework how the default `retry_limit` is calculated
|
26
|
+
* Numerous documentation updates
|
27
|
+
|
28
|
+
# 1.7.3 (2019-11-21)
|
29
|
+
|
30
|
+
* Do not crash if job class is not found on the resque-web server
|
31
|
+
|
32
|
+
# 1.7.2 (2019-11-21)
|
33
|
+
|
34
|
+
* Address part 2 of issue #158
|
35
|
+
|
36
|
+
# 1.7.1 (2019-07-10)
|
37
|
+
|
38
|
+
* Prevent `NoMethodError` when calculating `retry_delay`
|
39
|
+
|
40
|
+
# 1.7.0 (2019-06-15)
|
41
|
+
|
42
|
+
!!! [Potential] breaking changes -- details below !!!
|
43
|
+
|
44
|
+
* Remove support for `args_for_retry` -- it has been deprecated for almost 5
|
45
|
+
years
|
46
|
+
* Work w/ shallow-clone(s) of `args` in `MultipleWithRetrySuppression#save` and
|
47
|
+
`Retry.retry_args`
|
48
|
+
* Remove deprecated options from `Gem::Specification`
|
49
|
+
* Clean-up formatting in HISTORY.md
|
50
|
+
|
51
|
+
# 1.6.0 (2019-04-21)
|
52
|
+
|
53
|
+
* Clean-up / refactoring in preparation for a release (`ruby` deprecations,
|
54
|
+
etc.)
|
55
|
+
* Loosen version requirement to allow resque v2.0 and up (@peret)
|
56
|
+
|
57
|
+
# 1.5.3 (2018-11-26)
|
58
|
+
|
59
|
+
* Monkey patch in the `requeue_queue` method onto the `Resque::Failure` backend
|
60
|
+
(this _should_ be a temporary fix)
|
61
|
+
|
62
|
+
# 1.5.2 (2018-07-16)
|
63
|
+
|
64
|
+
* Remove build support for `ruby < 2.3`, `jruby < 9.1` and `rbx`
|
65
|
+
* Improving custom retry criteria documentation (@iloveitaly)
|
66
|
+
|
67
|
+
# 1.5.1 (2018-01-07)
|
68
|
+
|
69
|
+
* Added build support for `ruby-2.2.x`, `ruby-2.3.x`, `ruby-2.4.x` and
|
70
|
+
`ruby-2.5.x`
|
71
|
+
* Dropped build support for `ruby-1.9.3` and `ruby-2.0.0` (these versions are
|
72
|
+
no unsupported)
|
73
|
+
* Fix some deprecation warnings in tests
|
74
|
+
* Feature: If no exact exception class is present in `@retry_exceptions` hash,
|
75
|
+
try to find closest superclass (@fanfilmu)
|
76
|
+
* Feature: When running Resque inline, explicitly don't try to retry, don't
|
77
|
+
touch Redis (@michaelglass)
|
2
78
|
|
3
79
|
# 1.5.0 (2015-10-24)
|
4
80
|
|
@@ -20,25 +96,35 @@
|
|
20
96
|
## 1.3.0 (2014-07-25)
|
21
97
|
|
22
98
|
* Adjust gem dependency on `resque-scheduler` to ~> 3.0
|
23
|
-
* Deprecated: `args_for_retry` in favor of `retry_args` (will output deprecation
|
24
|
-
|
99
|
+
* Deprecated: `args_for_retry` in favor of `retry_args` (will output deprecation
|
100
|
+
warnings if your using the older method).
|
101
|
+
* Feature: Allow changing the args for a given exception using
|
102
|
+
`retry_args_for_exception` (@jonp)
|
25
103
|
* Feature: Allow setting `@expire_retry_key_after` on the fly (@orenmazor)
|
26
104
|
|
27
105
|
## 1.2.1 (2014-06-09)
|
28
106
|
|
29
|
-
* Fixed Kernel.rand: "invalid argument - 0.0 (ArgumentError)" error with
|
107
|
+
* Fixed Kernel.rand: "invalid argument - 0.0 (ArgumentError)" error with
|
108
|
+
"ExponentialBackoff" (on "Rubinius") when `retry_delay_multiplicand_min` and
|
109
|
+
`retry_delay_multiplicand_max` were the same value (@saizai)
|
30
110
|
|
31
111
|
## 1.2.0 (2014-05-19)
|
32
112
|
|
33
|
-
* Fixed scenario where job does not get retried correctly when `perform` is not
|
34
|
-
|
35
|
-
* Feature:
|
113
|
+
* Fixed scenario where job does not get retried correctly when `perform` is not
|
114
|
+
called as expected.
|
115
|
+
* Feature: Optional `@expire_retry_key_after` settings; expires retry counters
|
116
|
+
from redis to save you cleaning up stale state.
|
117
|
+
* Feature: Expose inner-workings of plugin through debug messages using
|
118
|
+
`Resque.logger` (when logging level is Logger:DEBUG).
|
36
119
|
|
37
120
|
## 1.1.4 (2014-03-17)
|
38
121
|
|
39
|
-
* Fixed displaying retry information in resque web interface, caused by
|
40
|
-
|
41
|
-
* Feature: Allow
|
122
|
+
* Fixed displaying retry information in resque web interface, caused by
|
123
|
+
`Resque::Helpers` being deprecated.
|
124
|
+
* Feature: Allow `@fatal_exceptions` as inverse of `@retry_exceptions`, when
|
125
|
+
a fatal exception is raised the job will be immediately fail.
|
126
|
+
* Feature: Allow a random retry delay (within a range) when using exponential
|
127
|
+
backoff strategy.
|
42
128
|
|
43
129
|
## 1.1.1 (2014-03-12)
|
44
130
|
|
@@ -47,20 +133,25 @@
|
|
47
133
|
## 1.1.0 (2014-03-12)
|
48
134
|
|
49
135
|
* Remove dependence on `Resque::Helpers`, will be removed in Resque 2.0
|
50
|
-
* Use SHA1 for default `#retry_identifier` to prevents issues with long args
|
136
|
+
* Use SHA1 for default `#retry_identifier` to prevents issues with long args
|
137
|
+
gobbling space.
|
51
138
|
* Minimum version of Resque is now ~> 1.25
|
52
139
|
|
53
140
|
## 1.0.0 (2012-09-07)
|
54
141
|
|
55
142
|
** !!! WARNING !!! INCLUDES NON-BACKWARDS COMPATIBLE CHANGES **
|
56
143
|
|
57
|
-
* Fixed issues related to
|
58
|
-
* Minimum gem dependency versions changed: resque >= 1.10.0, resque-scheduler
|
59
|
-
|
60
|
-
*
|
61
|
-
|
144
|
+
* Fixed issues related to infinite job retries and v1.20.0 of resque.
|
145
|
+
* Minimum gem dependency versions changed: resque >= 1.10.0, resque-scheduler
|
146
|
+
>= 1.9.9
|
147
|
+
* Feature: Setting `@retry_job_delegate` allows you to separate the original job
|
148
|
+
from a the retry job. (@tanob/@jniesen)
|
149
|
+
* Web interface will work without needing to `require` your job code. (n.b.
|
150
|
+
less details available via web).
|
151
|
+
* IMPORTANT: `#identifier` method has been namespaced to `#retry_identifier`.
|
62
152
|
* Bugfix: `Remove` button on retry web interface was not working.
|
63
|
-
* Feature: Allow `tagging` exceptions with a module instead of an exception
|
153
|
+
* Feature: Allow `tagging` exceptions with a module instead of an exception
|
154
|
+
class. (@tils - Tilmann Singer)
|
64
155
|
|
65
156
|
## 0.2.2 (2011-12-08)
|
66
157
|
|
@@ -68,7 +159,8 @@
|
|
68
159
|
|
69
160
|
## 0.2.1 (2011-11-23)
|
70
161
|
|
71
|
-
* Bugfix: Fixed error when we tried to parse a number/string as JSON on the
|
162
|
+
* Bugfix: Fixed error when we tried to parse a number/string as JSON on the
|
163
|
+
reque-retry web interface.
|
72
164
|
|
73
165
|
## 0.2.0 (2011-11-22)
|
74
166
|
|
@@ -78,9 +170,10 @@
|
|
78
170
|
PREVIOUSLY: 0 == infinite retries.
|
79
171
|
NOW: -1 == infinite retries; 0 == means never retry.
|
80
172
|
|
81
|
-
* Bugfix: `#redis_retry_key` incorrectly built key when custom identifier was
|
173
|
+
* Bugfix: `#redis_retry_key` incorrectly built key when custom identifier was
|
174
|
+
used. (Bogdan Gusiev)
|
82
175
|
* Feature: Ability to sleep worker after re-queuing a job, may be used to bias
|
83
|
-
|
176
|
+
against the same worker from picking up the job again. (Michael Keirnan)
|
84
177
|
* Feature: Ability to remove retry jobs using resque-web. (Thiago Morello)
|
85
178
|
* Added example demo application.
|
86
179
|
* Added Bundler `Gemfile`.
|
@@ -110,7 +203,8 @@
|
|
110
203
|
## 0.0.2 (2010-05-06)
|
111
204
|
|
112
205
|
* Bugfix: Were calling non-existent method to delete redis key.
|
113
|
-
* Delay no-longer falls back to `sleep`. resque-scheduler is a required
|
206
|
+
* Delay no-longer falls back to `sleep`. resque-scheduler is a required
|
207
|
+
dependancy.
|
114
208
|
* Redis key doesn't include ending colon `:` if no args were passed to the job.
|
115
209
|
|
116
210
|
## 0.0.1 (2010-04-27)
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
resque-retry
|
2
2
|
============
|
3
3
|
|
4
|
-
A [Resque][resque] plugin. Requires Resque ~> 1.25 & [resque-scheduler][resque-scheduler] ~> 4.0.
|
4
|
+
A [Resque][resque] plugin. Requires Resque ~> 1.25 or Resque ~> 2.0 & [resque-scheduler][resque-scheduler] ~> 4.0.
|
5
5
|
|
6
6
|
This gem provides retry, delay and exponential backoff support for resque jobs.
|
7
7
|
|
@@ -183,9 +183,10 @@ Here are a list of the options provided (click to jump):
|
|
183
183
|
* [Job Retry Identifier/Key](#retry_key)
|
184
184
|
* [Expire Retry Counters From Redis](#expire)
|
185
185
|
* [Try Again and Give Up Callbacks](#callbacks)
|
186
|
+
* [Ignored Exceptions](#ignored)
|
186
187
|
* [Debug Plugin Logging](#debug_log)
|
187
188
|
|
188
|
-
### <a name="retry_defaults"></a> Retry Defaults
|
189
|
+
### <a name="retry_defaults"></a> Retry Defaults
|
189
190
|
|
190
191
|
Retry the job **once** on failure, with zero delay.
|
191
192
|
```ruby
|
@@ -223,7 +224,48 @@ end
|
|
223
224
|
The above modification will allow your job to retry up to 10 times, with a delay
|
224
225
|
of 120 seconds, or 2 minutes between retry attempts.
|
225
226
|
|
226
|
-
You can override the `retry_delay` method to set the delay value dynamically.
|
227
|
+
You can override the `retry_delay` method to set the delay value dynamically. For example:
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
class ExampleJob
|
231
|
+
extend Resque::Plugins::Retry
|
232
|
+
@queue = :testing
|
233
|
+
|
234
|
+
def self.retry_delay(exception_class)
|
235
|
+
if exception_class == SocketError
|
236
|
+
10
|
237
|
+
else
|
238
|
+
1
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
def self.perform(*args)
|
243
|
+
heavy_lifting
|
244
|
+
end
|
245
|
+
end
|
246
|
+
```
|
247
|
+
|
248
|
+
Or, if you'd like the delay to be dependent on job arguments:
|
249
|
+
|
250
|
+
```ruby
|
251
|
+
class ExampleJob
|
252
|
+
extend Resque::Plugins::Retry
|
253
|
+
@queue = :testing
|
254
|
+
|
255
|
+
def self.retry_delay(exception, *args)
|
256
|
+
# the delay is dependent on the arguments passed to the job
|
257
|
+
# in this case, "3" is passed as the arg and that is used as the delay
|
258
|
+
# make sure this method returns a integer
|
259
|
+
args.first.to_i
|
260
|
+
end
|
261
|
+
|
262
|
+
def self.perform(*args)
|
263
|
+
heavy_lifting
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
Resque.enqueue(ExampleJob, '3')
|
268
|
+
```
|
227
269
|
|
228
270
|
### <a name="sleep"></a> Sleep After Requeuing
|
229
271
|
|
@@ -317,7 +359,12 @@ You may also want to specify different retry delays for different exception
|
|
317
359
|
types. You may optionally set `@retry_exceptions` to a hash where the keys are
|
318
360
|
your specific exception classes to retry on, and the values are your retry
|
319
361
|
delays in seconds or an array of retry delays to be used similar to exponential
|
320
|
-
backoff.
|
362
|
+
backoff. `resque-retry` will attempt to determine your retry strategy's
|
363
|
+
`@retry_limit` based on your specified `@retry_exceptions`. If, however, you
|
364
|
+
define `@retry_limit` explicitly, you should define `@retry_limit` such that it
|
365
|
+
allows for your retry strategies to complete. If your `@retry_limit` is less
|
366
|
+
than the number of desired retry attempts defined in `@retry_exceptions`, your
|
367
|
+
job will only retry `@retry_limit` times.
|
321
368
|
```ruby
|
322
369
|
class DeliverSMS
|
323
370
|
extend Resque::Plugins::Retry
|
@@ -332,9 +379,15 @@ end
|
|
332
379
|
```
|
333
380
|
|
334
381
|
In the above example, Resque would retry any `DeliverSMS` jobs which throw a
|
335
|
-
`NetworkError` or `SystemCallError`.
|
336
|
-
|
337
|
-
|
382
|
+
`NetworkError` or `SystemCallError`. The `@retry_limit` would be inferred to be
|
383
|
+
2 based on the longest retry strategy defined in `@retry_exceptions`. If the job
|
384
|
+
throws a `NetworkError` it will be retried 30 seconds later with a subsequent
|
385
|
+
retry 30 seconds after that. If it throws a `SystemCallError` it will first
|
386
|
+
retry 120 seconds later then a subsequent retry attempt 240 seconds later. If
|
387
|
+
the job fails due to a `NetworkError`, Resque would retry the job in 30 seconds.
|
388
|
+
If the job fails a second time, this time due to a `SystemCallError`, the next
|
389
|
+
retry would occur 240 seconds later as specified in the `SystemCallError`
|
390
|
+
array defined in `@retry_exceptions`.
|
338
391
|
|
339
392
|
### <a name="fail_fast"></a> Fail Fast For Specific Exceptions
|
340
393
|
|
@@ -357,6 +410,8 @@ In the above example, Resque would retry any `DeliverSMS` jobs that throw any
|
|
357
410
|
type of error other than `NetworkError`. If the job throws a `NetworkError` it
|
358
411
|
will be marked as "failed" immediately.
|
359
412
|
|
413
|
+
You should use either `@fatal_exceptions` or `@retry_exceptions`. If you specify `@fatal_exceptions` the `@retry_exceptions` are ignored.
|
414
|
+
|
360
415
|
### <a name="custom_check"></a> Custom Retry Criteria Check Callbacks
|
361
416
|
|
362
417
|
You may define custom retry criteria callbacks:
|
@@ -368,11 +423,11 @@ class TurkWorker
|
|
368
423
|
@retry_exceptions = [NetworkError]
|
369
424
|
|
370
425
|
retry_criteria_check do |exception, *args|
|
371
|
-
if exception.message =~ /
|
372
|
-
|
373
|
-
else
|
374
|
-
true # its okay for a retry attempt to continue.
|
426
|
+
if exception.message =~ /SpecialErrorMessageToRetry/
|
427
|
+
return true
|
375
428
|
end
|
429
|
+
|
430
|
+
false
|
376
431
|
end
|
377
432
|
|
378
433
|
def self.perform(job_id)
|
@@ -385,9 +440,18 @@ Similar to the previous example, this job will retry if either a
|
|
385
440
|
`NetworkError` (or subclass) exception is thrown **or** any of the callbacks
|
386
441
|
return true.
|
387
442
|
|
443
|
+
You'll want to return false by default in the `retry_criteria_check` callback since
|
444
|
+
the result of this callback is OR'd with the result of your `retry_exceptions` or
|
445
|
+
`fatal_exceptions` configuration. In other words, if you returned true your
|
446
|
+
`retry_exceptions` configuration would never be used.
|
447
|
+
|
448
|
+
If you want to AND the result of `fatal_exceptions` or `retry_exceptions` with
|
449
|
+
custom retry criteria, you'll need to implement your own logic in a `retry_criteria_check`
|
450
|
+
to check for `fatal_exceptions` or `retry_exceptions`.
|
451
|
+
|
388
452
|
You can also register a retry criteria check with a Symbol if the method is
|
389
453
|
already defined on the job class:
|
390
|
-
```
|
454
|
+
```ruby
|
391
455
|
class AlwaysRetryJob
|
392
456
|
extend Resque::Plugins::Retry
|
393
457
|
|
@@ -397,8 +461,9 @@ class AlwaysRetryJob
|
|
397
461
|
true
|
398
462
|
end
|
399
463
|
end
|
464
|
+
```
|
400
465
|
|
401
|
-
Use `@retry_exceptions = []` to **only** use your custom retry criteria checks
|
466
|
+
Use `@retry_exceptions = []` and `@fatal_exceptions = []` to **only** use your custom retry criteria checks
|
402
467
|
to determine if the job should retry.
|
403
468
|
|
404
469
|
NB: Your callback must be able to accept the exception and job arguments as
|
@@ -419,7 +484,7 @@ class DeliverViaSMSC
|
|
419
484
|
[999, mt_message]
|
420
485
|
end
|
421
486
|
|
422
|
-
self.perform(smsc_id, mt_message)
|
487
|
+
def self.perform(smsc_id, mt_message)
|
423
488
|
heavy_lifting
|
424
489
|
end
|
425
490
|
end
|
@@ -439,11 +504,52 @@ class DeliverViaSMSC
|
|
439
504
|
[999, mt_message + exception.message]
|
440
505
|
end
|
441
506
|
|
442
|
-
self.perform(smsc_id, mt_message)
|
507
|
+
def self.perform(smsc_id, mt_message)
|
508
|
+
heavy_lifting
|
509
|
+
end
|
510
|
+
end
|
511
|
+
```
|
512
|
+
|
513
|
+
### Custom Retry Queues
|
514
|
+
|
515
|
+
By default, when a job is retried, it is added to the `@queue` specified in the worker. However, you may want to push the job into another (lower or higher priority) queue when the job fails. You can do this by dynamically specifying the retry queue. For example:
|
516
|
+
|
517
|
+
```ruby
|
518
|
+
class ExampleJob
|
519
|
+
extend Resque::Plugins::Retry
|
520
|
+
@queue = :testing
|
521
|
+
@retry_delay = 1
|
522
|
+
|
523
|
+
def self.work(*args)
|
524
|
+
user_id, user_mode, record_id = *args
|
525
|
+
|
526
|
+
Resque.enqueue_to(
|
527
|
+
target_queue_for_args(user_id, user_mode, record_id),
|
528
|
+
self,
|
529
|
+
*args
|
530
|
+
)
|
531
|
+
end
|
532
|
+
|
533
|
+
def self.retry_queue(exception, *args)
|
534
|
+
target_queue_for_args(*args)
|
535
|
+
end
|
536
|
+
|
537
|
+
def self.perform(*args)
|
443
538
|
heavy_lifting
|
444
539
|
end
|
540
|
+
|
541
|
+
def self.target_queue_for_args(*args)
|
542
|
+
user_id, user_mode, record_id = *args
|
543
|
+
|
544
|
+
if user_mode
|
545
|
+
'high'
|
546
|
+
else
|
547
|
+
'low'
|
548
|
+
end
|
549
|
+
end
|
445
550
|
end
|
446
551
|
```
|
552
|
+
|
447
553
|
### <a name="retry_key"></a> Job Retry Identifier/Key
|
448
554
|
|
449
555
|
The retry attempt is incremented and stored in a Redis key. The key is built
|
@@ -466,7 +572,7 @@ class DeliverSMS
|
|
466
572
|
"#{mobile_number}:#{mt_id}"
|
467
573
|
end
|
468
574
|
|
469
|
-
self.perform(mt_id, mobile_number, message)
|
575
|
+
def self.perform(mt_id, mobile_number, message)
|
470
576
|
heavy_lifting
|
471
577
|
end
|
472
578
|
end
|
@@ -482,7 +588,7 @@ class DeliverSMS
|
|
482
588
|
@queue = :mt_messages
|
483
589
|
@expire_retry_key_after = 3600 # expire key after `retry_delay` plus 1 hour
|
484
590
|
|
485
|
-
self.perform(mt_id, mobile_number, message)
|
591
|
+
def self.perform(mt_id, mobile_number, message)
|
486
592
|
heavy_lifting
|
487
593
|
end
|
488
594
|
end
|
@@ -490,7 +596,7 @@ end
|
|
490
596
|
|
491
597
|
This saves you from having to run a "house cleaning" or "errand" job.
|
492
598
|
|
493
|
-
The
|
599
|
+
The expiry timeout is "pushed forward" or "touched" after each failure to
|
494
600
|
ensure it's not expired too soon.
|
495
601
|
|
496
602
|
### <a name="callbacks"></a> Try Again and Give Up Callbacks
|
@@ -512,7 +618,7 @@ _not_ retrying, you can add a `give_up_callback`:
|
|
512
618
|
```ruby
|
513
619
|
class LoggedJob
|
514
620
|
extend Resque::Plugins::Retry
|
515
|
-
|
621
|
+
|
516
622
|
give_up_callback do |exception, *args|
|
517
623
|
logger.error("Received #{exception}, job #{self.name} failed with #{args}")
|
518
624
|
end
|
@@ -524,10 +630,10 @@ the job class:
|
|
524
630
|
```ruby
|
525
631
|
class LoggedJob
|
526
632
|
extend Resque::Plugins::Retry
|
527
|
-
|
633
|
+
|
528
634
|
give_up_callback :log_give_up
|
529
635
|
|
530
|
-
def self.log_give_up(
|
636
|
+
def self.log_give_up(exception, *args)
|
531
637
|
logger.error("Received #{exception}, job #{self.name} failed with #{args}")
|
532
638
|
end
|
533
639
|
end
|
@@ -557,11 +663,42 @@ Warning: Make sure your callbacks do not throw any exceptions. If they do,
|
|
557
663
|
subsequent callbacks will not be triggered, and the job will not be retried
|
558
664
|
(if it was trying again). The retry counter also will not be reset.
|
559
665
|
|
666
|
+
### <a name="ignored"></a> Ignored Exceptions
|
667
|
+
If there is an exception for which you want to retry, but you don't want it to
|
668
|
+
increment your retry counter, you can add it to `@ignore_exceptions`.
|
669
|
+
|
670
|
+
One use case: Restarting your workers triggers a `Resque::TermException`. You
|
671
|
+
may want your workers to retry the job that they were working on, but without
|
672
|
+
incrementing the retry counter.
|
673
|
+
|
674
|
+
```ruby
|
675
|
+
class RestartResilientJob
|
676
|
+
extend Resque::Plugins::Retry
|
677
|
+
|
678
|
+
@retry_exceptions = [Resque::TermException]
|
679
|
+
@ignore_exceptions = [Resque::TermException]
|
680
|
+
end
|
681
|
+
```
|
682
|
+
|
683
|
+
Reminder: `@ignore_exceptions` should be a subset of `@retry_exceptions`.
|
684
|
+
|
560
685
|
### <a name="debug_log"></a> Debug Plugin Logging
|
561
686
|
|
562
687
|
The inner-workings of the plugin are output to the Resque [Logger](https://github.com/resque/resque/wiki/Logging)
|
563
688
|
when `Resque.logger.level` is set to `Logger::DEBUG`.
|
564
689
|
|
690
|
+
Add `VVERBOSE=true` as an environment variable to easily set the log level to debug.
|
691
|
+
|
692
|
+
### Testing
|
693
|
+
|
694
|
+
To run a specific test and inspect logging output
|
695
|
+
|
696
|
+
```
|
697
|
+
bundle exec rake TEST=the_test_file.rb VVERBOSE=true
|
698
|
+
```
|
699
|
+
|
700
|
+
There are many example jobs implementing various use-cases for this gem in `test_jobs.rb`
|
701
|
+
|
565
702
|
Contributing/Pull Requests
|
566
703
|
--------------------------
|
567
704
|
|