1
1
resque-retry
2
2
============
3
3
4
- A [ Resque] [ rq ] plugin. Requires Resque ~ > 1.25 & [ resque-scheduler] [ rqs ] ~ > 4.0.
4
+ A [ Resque] [ resque ] plugin. Requires Resque ~ > 1.25 & [ resque-scheduler] [ resque-scheduler ] ~ > 4.0.
5
5
6
6
This gem provides retry, delay and exponential backoff support for resque jobs.
7
7
@@ -18,19 +18,20 @@ Install & Quick Start
18
18
---------------------
19
19
20
20
To install:
21
+ ```
22
+ $ gem install resque-retry
23
+ ```
21
24
22
- $ gem install resque-retry
23
-
24
- If you're using [ Bundler] [ bundler ] to manage your dependencies, you should add `gem
25
- 'resque-retry'` to your projects ` Gemfile`.
25
+ If you're using [ Bundler] [ bundler ] to manage your dependencies, you should add
26
+ ` gem 'resque-retry' ` to your ` Gemfile ` .
26
27
27
28
Add this to your ` Rakefile ` :
28
29
``` ruby
29
30
require ' resque/tasks'
30
31
require ' resque/scheduler/tasks'
31
32
```
32
33
33
- The delay between retry attempts is provided by [ resque-scheduler] [ rqs ] .
34
+ The delay between retry attempts is provided by [ resque-scheduler] [ resque-scheduler ] .
34
35
You'll want to run the scheduler process, otherwise delayed retry attempts
35
36
will never perform:
36
37
```
@@ -79,7 +80,8 @@ actually completed successfully just by just using the resque-web interface.
79
80
80
81
### Failure Backend
81
82
82
- ` MultipleWithRetrySuppression ` is a multiple failure backend, with retry suppression.
83
+ ` MultipleWithRetrySuppression ` is a multiple failure backend, with retry
84
+ suppression.
83
85
84
86
Here's an example, using the Redis failure backend:
85
87
``` ruby
@@ -92,34 +94,33 @@ Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
92
94
Resque ::Failure .backend = Resque ::Failure ::MultipleWithRetrySuppression
93
95
```
94
96
95
- If a job fails, but ** can and will** retry, the failure details wont be
96
- logged in the Redis failed queue * (visible via resque-web)* .
97
+ If a job fails, but ** can and will** retry, the failure details wont be logged
98
+ in the Redis failed queue * (visible via resque-web)* .
97
99
98
100
If the job fails, but ** can't or won't** retry, the failure will be logged in
99
101
the Redis failed queue, like a normal failure * (without retry)* would.
100
102
101
103
### Resque Web Additions
102
104
103
105
If you're using the ` MultipleWithRetrySuppression ` failure backend, you should
104
- also checkout the resque-web additions!
106
+ also checkout the ` resque-web ` additions!
105
107
106
108
The new Retry tab displays delayed jobs with retry information; the number of
107
109
attempts and the exception details from the last failure.
108
110
109
111
110
112
### Configuring and running the Resque-Web Interface
111
113
112
- #### Using a Rack configuration:
113
-
114
- One alternative is to use a rack configuration file. To use this, make
115
- sure you include this in your ` config.ru ` or similar file:
114
+ #### Using a Rack configuration:
116
115
116
+ One alternative is to use a rack configuration file. To use this, make sure you
117
+ include this in your ` config.ru ` or similar file:
117
118
``` ruby
118
119
require ' resque-retry'
119
120
require ' resque-retry/server'
120
121
121
122
# Make sure to require your workers & application code below this line:
122
- # require '[path]/[to]/[jobs]/your_worker'
123
+ # require '[path]/[to]/[jobs]/your_worker'
123
124
124
125
# Run the server
125
126
run Resque ::Server .new
@@ -132,33 +133,30 @@ rackup -p 9292 config.ru
132
133
133
134
When using bundler, you can also run the server like this:
134
135
```
135
- bundle exec rackup -p 9292 config.ru
136
+ bundle exec rackup -p 9292 config.ru
136
137
```
137
138
138
139
139
140
#### Using the 'resque-web' command with a configuration file:
140
141
141
- Another alternative is to use resque's built-in 'resque-web' command with
142
- the additional resque-retry tabs. In order to do this, you must first create
143
- a configuration file. For the sake of this example we'll create the configuration
144
- file in a 'config' directory, and name it 'resque_web_config.rb'. In practice
145
- you could rename this configuration file to anything you'd like and place in your
146
- project in any directory of your choosing. The contents of the configuration file
142
+ Another alternative is to use resque's built-in 'resque-web' command with the
143
+ additional resque-retry tabs. In order to do this, you must first create a
144
+ configuration file. For the sake of this example we'll create the configuration
145
+ file in a 'config' directory, and name it 'resque_web_config.rb'. In practice
146
+ you could rename this configuration file to anything you like and place in your
147
+ project in a directory of your choosing. The contents of the configuration file
147
148
would look like this:
148
-
149
149
``` ruby
150
150
# [app_dir]/config/resque_web_config.rb
151
151
require ' resque-retry'
152
152
require ' resque-retry/server'
153
153
154
154
# Make sure to require your workers & application code below this line:
155
- # require '[path]/[to]/[jobs]/your_worker'
156
-
155
+ # require '[path]/[to]/[jobs]/your_worker'
157
156
```
158
157
159
158
Once you have the configuration file ready, you can pass the configuration file
160
159
to the resque-web command as a parameter, like so:
161
-
162
160
```
163
161
resque-web [app_dir]/config/resque_web_config.rb
164
162
```
@@ -170,8 +168,8 @@ Retry Options & Logic
170
168
Please take a look at the [ yardoc] ( http://rubydoc.info/gems/resque-retry ) /code
171
169
for more details on methods you may wish to override.
172
170
173
- Customisation is pretty easy, the below examples should give you
174
- some ideas =), adapt for your own usage and feel free to pick and mix!
171
+ Customisation is pretty easy, the below examples should give you some ideas =),
172
+ adapt for your own usage and feel free to pick and mix!
175
173
176
174
### Retry Defaults
177
175
@@ -208,11 +206,10 @@ class DeliverWebHook
208
206
end
209
207
```
210
208
211
- The above modification will allow your job to retry up to 10 times, with
212
- a delay of 120 seconds, or 2 minutes between retry attempts.
209
+ The above modification will allow your job to retry up to 10 times, with a delay
210
+ of 120 seconds, or 2 minutes between retry attempts.
213
211
214
- Alternatively you could override the ` retry_delay ` method to do something
215
- more special.
212
+ You can override the ` retry_delay ` method to set the delay value dynamically.
216
213
217
214
### Sleep After Requeuing
218
215
@@ -235,14 +232,14 @@ end
235
232
This retries the job once and causes the worker that failed to sleep for 5
236
233
seconds after requeuing the job. If there are multiple workers in the system
237
234
this allows the job to be retried immediately while the original worker heals
238
- itself.For example failed jobs may cause other (non-worker) OS processes to
239
- die. A system monitor such as [ god] [ god ] can fix the server while the job is
240
- being retried on a different worker.
235
+ itself. For example failed jobs may cause other (non-worker) OS processes to
236
+ die. A system monitor such as [ monit ] [ monit ] or [ god] [ god ] can fix the server
237
+ while the job is being retried on a different worker.
241
238
242
239
` @sleep_after_requeue ` is independent of ` @retry_delay ` . If you set both, they
243
240
both take effect.
244
241
245
- You can override the method ` sleep_after_requeue ` to set the sleep value
242
+ You can override the ` sleep_after_requeue ` method to set the sleep value
246
243
dynamically.
247
244
248
245
### Exponential Backoff
@@ -263,17 +260,17 @@ end
263
260
```
264
261
key: m = minutes, h = hours
265
262
266
- no delay , 1m, 10m, 1h, 3h, 6h
263
+ 0s , 1m, 10m, 1h, 3h, 6h
267
264
@backoff_strategy = [0, 60, 600, 3600, 10800, 21600]
268
265
@retry_delay_multiplicand_min = 1.0
269
266
@retry_delay_multiplicand_max = 1.0
270
267
```
271
268
272
- The first delay will be 0 seconds, the 2nd will be 60 seconds, etc...
273
- Again, tweak to your own needs.
269
+ The first delay will be 0 seconds, the 2nd will be 60 seconds, etc... Again,
270
+ tweak to your own needs.
274
271
275
- The number of retries is equal to the size of the ` backoff_strategy `
276
- array, unless you set ` retry_limit ` yourself.
272
+ The number of retries is equal to the size of the ` backoff_strategy ` array,
273
+ unless you set ` retry_limit ` yourself.
277
274
278
275
The delay values will be multiplied by a random ` Float ` value between
279
276
` retry_delay_multiplicand_min ` and ` retry_delay_multiplicand_max ` (both have a
@@ -284,8 +281,8 @@ them all retried on the same schedule.
284
281
285
282
### Retry Specific Exceptions
286
283
287
- The default will allow a retry for any type of exception. You may change
288
- it so only specific exceptions are retried using ` retry_exceptions ` :
284
+ The default will allow a retry for any type of exception. You may change it so
285
+ only specific exceptions are retried using ` retry_exceptions ` :
289
286
``` ruby
290
287
class DeliverSMS
291
288
extend Resque ::Plugins ::Retry
@@ -305,8 +302,8 @@ exception is thrown.
305
302
You may also want to specify different retry delays for different exception
306
303
types. You may optionally set ` @retry_exceptions ` to a hash where the keys are
307
304
your specific exception classes to retry on, and the values are your retry
308
- delays in seconds or an array of retry delays to be used similar to
309
- exponential backoff.
305
+ delays in seconds or an array of retry delays to be used similar to exponential
306
+ backoff.
310
307
``` ruby
311
308
class DeliverSMS
312
309
extend Resque ::Plugins ::Retry
@@ -379,8 +376,8 @@ job should retry.
379
376
380
377
### Retry Arguments
381
378
382
- You may override ` retry_args ` , which is passed the current
383
- job arguments, to modify the arguments for the next retry attempt.
379
+ You may override ` retry_args ` , which is passed the current job arguments, to
380
+ modify the arguments for the next retry attempt.
384
381
``` ruby
385
382
class DeliverViaSMSC
386
383
extend Resque ::Plugins ::Retry
@@ -397,10 +394,10 @@ class DeliverViaSMSC
397
394
end
398
395
```
399
396
400
- Alternatively, if you require finer control of the args based on the
401
- exception thrown, you may override ` retry_args_for_exception ` , which is passed
402
- the exception and the current job arguments, to modify the arguments for the
403
- next retry attempt.
397
+ Alternatively, if you require finer control of the args based on the exception
398
+ thrown, you may override ` retry_args_for_exception ` , which is passed the
399
+ exception and the current job arguments, to modify the arguments for the next
400
+ retry attempt.
404
401
``` ruby
405
402
class DeliverViaSMSC
406
403
extend Resque ::Plugins ::Retry
@@ -418,15 +415,15 @@ end
418
415
```
419
416
### Job Retry Identifier/Key
420
417
421
- The retry attempt is incremented and stored in a Redis key. The key is
422
- built using the ` retry_identifier ` . If you have a lot of arguments or really long
418
+ The retry attempt is incremented and stored in a Redis key. The key is built
419
+ using the ` retry_identifier ` . If you have a lot of arguments or really long
423
420
ones, you should consider overriding ` retry_identifier ` to define a more precise
424
421
or loose custom retry identifier.
425
422
426
- The default retry identifier is just your job arguments joined with a dash ` - ` .
423
+ The default identifier is just your job arguments joined with a dash ` '-' ` .
427
424
428
- By default the key uses this format:
429
- ` resque-retry:<job class name>:<retry_identifier> ` .
425
+ By default the key uses this format:
426
+ ` ' resque-retry:<job class name>:<retry_identifier>' ` .
430
427
431
428
Or you can define the entire key by overriding ` redis_retry_key ` .
432
429
``` ruby
448
445
449
446
Allow the Redis to expire stale retry counters from the database by setting
450
447
` @expire_retry_key_after ` :
451
-
452
448
``` ruby
453
449
class DeliverSMS
454
450
extend Resque ::Plugins ::Retry
@@ -459,13 +455,12 @@ class DeliverSMS
459
455
heavy_lifting
460
456
end
461
457
end
462
-
463
458
```
464
459
465
460
This saves you from having to run a "house cleaning" or "errand" job.
466
461
467
462
The expiary timeout is "pushed forward" or "touched" after each failure to
468
- ensure its not expired too soon.
463
+ ensure it's not expired too soon.
469
464
470
465
### Debug Plugin Logging
471
466
@@ -483,7 +478,8 @@ Contributing/Pull Requests
483
478
* Send us a pull request. Bonus points for topic branches.
484
479
* If you edit the gemspec/version etc, please do so in another commit.
485
480
486
- [ god ] : http://github.com/mojombo/god
487
- [ rq ] : http://github.com/resque/resque
488
- [ rqs ] : http://github.com/resque/resque-scheduler
481
+ [ monit ] : https://mmonit.com
482
+ [ god ] : http://godrb.com
483
+ [ resque ] : http://github.com/resque/resque
484
+ [ resque-scheduler ] : http://github.com/resque/resque-scheduler
489
485
[ bundler ] : http://bundler.io
0 commit comments