activejob-retry 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -28
- data/lib/active_job/retry.rb +5 -6
- data/lib/active_job/retry/version.rb +1 -1
- data/test/integration/queuing_test.rb +13 -0
- data/test/jobs/rescue_job.rb +1 -1
- data/test/support/integration/dummy_app_template.rb +8 -1
- data/test/support/integration/test_case_helpers.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e81c61b7e8ca2f2d5370d1e18535cc1c30a93caa
|
4
|
+
data.tar.gz: 617790d33f2c4ceafaae57a3d9021a642086fdc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b84443eca49518480e1750059f51ce6cca79c78b7d709dbb1e1d27a8ca8155a409d60122351671cbb6c4a823242ea120a024525b208ccdcf109aa4a56e7ecf6
|
7
|
+
data.tar.gz: 2f81fb5b728b58c31456679e9a91a95cb9b056c630455c4eb0cf7e5e5502689dca28c74c760be899564c7105364f99b301713a18d536bcbbfd14b1d520c09db9
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.3.0 - January 6, 2015
|
2
|
+
|
3
|
+
- `rescue_from` gets called only when all retries have failed, rather than before attempting to retry (patch by [@isaacseymour](https://github.com/isaacseymour)
|
4
|
+
|
1
5
|
## 0.2.0 - January 1, 2015
|
2
6
|
|
3
7
|
- Renamed retry_exceptions to retryable_exceptions (patch by [@greysteil](https://github.com/greysteil)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,38 +40,27 @@ class ProcessWebhook < ActiveJob::Base
|
|
40
40
|
end
|
41
41
|
```
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
: Maximum number of times to attempt the job (default: 1).
|
46
|
-
|
47
|
-
`unlimited_retries`
|
48
|
-
: If set to `true`, this job will be repeated indefinitely until in succeeds. Use with extreme caution.
|
49
|
-
|
50
|
-
`delay`
|
51
|
-
: Time between attempts (default: 0).
|
43
|
+
The retry will get executed before any `rescue_from` blocks, which will only get executed
|
44
|
+
if the exception is not going to be retried, or has failed the final retry.
|
52
45
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
`
|
57
|
-
|
46
|
+
#### constant_retry options
|
47
|
+
| Option | Default | Description |
|
48
|
+
|:---------------------- |:------- |:-------------- |
|
49
|
+
| `limit` | `1` | Maximum number of times to attempt the job (default: 1).
|
50
|
+
| `unlimited_retries` | `false` | If set to `true`, this job will be repeated indefinitely until in succeeds. Use with extreme caution.
|
51
|
+
| `delay` | `0` | Time between attempts (default: 0).
|
52
|
+
| `retryable_exceptions` | `nil` | A whitelist of exceptions to retry. When `nil`, all exceptions will result in a retry.
|
53
|
+
| `fatal_exceptions` | `[]` | A blacklist of exceptions to not retry (default: []).
|
58
54
|
|
59
55
|
#### variable_retry options
|
60
56
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
`min_delay_multiplier`
|
65
|
-
|
66
|
-
|
67
|
-
`
|
68
|
-
: The other end of the range for `min_delay_multiplier`. If one is supplied, both must be.
|
69
|
-
|
70
|
-
`retryable_exceptions`
|
71
|
-
: Same as for `constant_retry`.
|
72
|
-
|
73
|
-
`fatal_exceptions`
|
74
|
-
: Same as for `constant_retry`.
|
57
|
+
| Option | Default | Description |
|
58
|
+
|:---------------------- |:------- |:------------- |
|
59
|
+
| `delays` | | __required__ An array of delays between attempts. The first attempt will occur whenever you originally enqueued the job to happen.
|
60
|
+
| `min_delay_multiplier` | | If supplied, each delay will be multiplied by a random number between this and `max_delay_multiplier`.
|
61
|
+
| `max_delay_multiplier` | | The other end of the range for `min_delay_multiplier`. If one is supplied, both must be.
|
62
|
+
| `retryable_exceptions` | `nil` | Same as for [constant_retry](#constant_retry-options).
|
63
|
+
| `fatal_exceptions` | `[]` | Same as for [constant_retry](#constant_retry-options).
|
75
64
|
|
76
65
|
Contributing
|
77
66
|
------------
|
data/lib/active_job/retry.rb
CHANGED
@@ -83,23 +83,22 @@ module ActiveJob
|
|
83
83
|
# Performing the retries #
|
84
84
|
##########################
|
85
85
|
|
86
|
-
# Override `rescue_with_handler` to make sure our catch is
|
87
|
-
#
|
86
|
+
# Override `rescue_with_handler` to make sure our catch is before callbacks,
|
87
|
+
# so only run when the job is finally failing.
|
88
88
|
def rescue_with_handler(exception)
|
89
|
-
|
89
|
+
retry_or_reraise(exception) || super(exception)
|
90
90
|
end
|
91
91
|
|
92
92
|
private
|
93
93
|
|
94
94
|
def retry_or_reraise(exception)
|
95
95
|
unless self.class.backoff_strategy.should_retry?(retry_attempt, exception)
|
96
|
-
|
96
|
+
return false
|
97
97
|
end
|
98
98
|
|
99
99
|
this_delay = self.class.backoff_strategy.retry_delay(retry_attempt, exception)
|
100
100
|
# TODO: This breaks DelayedJob and Resque for some weird ActiveSupport reason.
|
101
|
-
# logger.
|
102
|
-
# "Retrying (attempt #{retry_attempt + 1}, waiting #{this_delay}s)")
|
101
|
+
# logger.info("Retrying (attempt #{retry_attempt + 1}, waiting #{this_delay}s)")
|
103
102
|
@retry_attempt += 1
|
104
103
|
retry_job(wait: this_delay)
|
105
104
|
|
@@ -43,4 +43,17 @@ class QueuingTest < ActiveSupport::TestCase
|
|
43
43
|
wait_for_jobs_to_finish_for(5.seconds)
|
44
44
|
assert job_executed
|
45
45
|
end
|
46
|
+
|
47
|
+
test 'should call rescue_from only when retries have run out' do
|
48
|
+
TestJob.rescue_from(RuntimeError) { write_to_rescue_file }
|
49
|
+
TestJob.perform_later(@id, false, true)
|
50
|
+
|
51
|
+
wait_for_jobs_to_finish_for(2.seconds)
|
52
|
+
assert_not job_executed
|
53
|
+
refute rescue_executed
|
54
|
+
|
55
|
+
wait_for_jobs_to_finish_for(5.seconds)
|
56
|
+
assert_not job_executed
|
57
|
+
assert rescue_executed
|
58
|
+
end
|
46
59
|
end
|
data/test/jobs/rescue_job.rb
CHANGED
@@ -17,12 +17,19 @@ class TestJob < ActiveJob::Base
|
|
17
17
|
queue_as :integration_tests
|
18
18
|
constant_retry limit: 2, delay: 3
|
19
19
|
|
20
|
-
def perform(x, fail_first = false)
|
20
|
+
def perform(x, fail_first = false, fail_always = false)
|
21
21
|
raise "Failing first" if fail_first && retry_attempt == 1
|
22
|
+
raise "Failing always" if fail_always
|
22
23
|
|
23
24
|
File.open(Rails.root.join("tmp/\#{x}"), "w+") do |f|
|
24
25
|
f.write x
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
def write_to_rescue_file
|
30
|
+
File.open(Rails.root.join("tmp/\#{arguments.first}_rescue"), "w+") do |f|
|
31
|
+
f.write arguments.first
|
32
|
+
end
|
33
|
+
end
|
27
34
|
end
|
28
35
|
CODE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activejob-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Seymour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|