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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26e70483f72942ecc312de55cd5bd34280ff459a
4
- data.tar.gz: 771d1365fd7fc7581fced033b642ef4188e2e88d
3
+ metadata.gz: e81c61b7e8ca2f2d5370d1e18535cc1c30a93caa
4
+ data.tar.gz: 617790d33f2c4ceafaae57a3d9021a642086fdc7
5
5
  SHA512:
6
- metadata.gz: d486c2b1253b045158bdb2880c0b12a0a00ed3aa1d4378de4ce0420710ae8f5c9f775089ab44c80d122384bc3bbc1504cc42f678c6d473742ded17369108a9a6
7
- data.tar.gz: d9a91dd6a4beb9687d47fe9ce3df82fc5c29516a09e9d2d699fd017f6dc7b9522abdabecd7224a2952029c6d15ec38281652a64494ddaa00ce8c471183d1598b
6
+ metadata.gz: 6b84443eca49518480e1750059f51ce6cca79c78b7d709dbb1e1d27a8ca8155a409d60122351671cbb6c4a823242ea120a024525b208ccdcf109aa4a56e7ecf6
7
+ data.tar.gz: 2f81fb5b728b58c31456679e9a91a95cb9b056c630455c4eb0cf7e5e5502689dca28c74c760be899564c7105364f99b301713a18d536bcbbfd14b1d520c09db9
@@ -3,7 +3,7 @@ AllCops:
3
3
  - Rakefile
4
4
  Exclude:
5
5
  - .*/**/*
6
- - vendor/**
6
+ - vendor/**/*
7
7
  - test/**/*
8
8
 
9
9
  LineLength:
@@ -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)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activejob-retry (0.2.0)
4
+ activejob-retry (0.3.0)
5
5
  activejob (>= 4.2)
6
6
  activesupport (>= 4.2)
7
7
 
data/README.md CHANGED
@@ -40,38 +40,27 @@ class ProcessWebhook < ActiveJob::Base
40
40
  end
41
41
  ```
42
42
 
43
- #### constant_retry options
44
- `limit`
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
- `retryable_exceptions`
54
- : A whitelist of exceptions to retry (default: nil, i.e. all exceptions will result in a retry).
55
-
56
- `fatal_exceptions`
57
- : A blacklist of exceptions to not retry (default: []).
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
- `delays`
62
- : __required__ An array of delays between attempts. The first attempt will occur whenever you originally enqueued the job to happen.
63
-
64
- `min_delay_multiplier`
65
- : If supplied, each delay will be multiplied by a random number between this and `max_delay_multiplier`.
66
-
67
- `max_delay_multiplier`
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
  ------------
@@ -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 the last one, and doesn't
87
- # happen if the exception has already been caught in a `rescue_from`
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
- super || retry_or_reraise(exception)
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
- raise exception
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.log(Logger::INFO,
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
 
@@ -1,5 +1,5 @@
1
1
  module ActiveJob
2
2
  module Retry
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -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
@@ -2,7 +2,7 @@ require_relative '../support/job_buffer'
2
2
 
3
3
  class RescueJob < ActiveJob::Base
4
4
  include ActiveJob::Retry
5
- constant_retry limit: 2, delay: 0
5
+ constant_retry limit: 0, delay: 0
6
6
 
7
7
  class OtherError < StandardError; end
8
8
 
@@ -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
@@ -45,4 +45,8 @@ module TestCaseHelpers
45
45
  def job_executed
46
46
  Dummy::Application.root.join("tmp/#{@id}").exist?
47
47
  end
48
+
49
+ def rescue_executed
50
+ Dummy::Application.root.join("tmp/#{@id}_rescue").exist?
51
+ end
48
52
  end
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.2.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-02 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob