exp_retry 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5587b6563afaa1c777f7fadd3f6d1aadd925228a
4
- data.tar.gz: 445ad33d5d9172e57aa718c935928103141fdbfd
3
+ metadata.gz: ea9f2d770247bb54f9924524a61fc134c642bfb9
4
+ data.tar.gz: 93e6e3ca775f7dc85cab22bb928c7adda4370020
5
5
  SHA512:
6
- metadata.gz: f277a41856af529f43cdc700b0083c428afa872fedbdfd45f7fe0eaf2e9dabcdad23fc6a9a56967bf82ea2b48b707aedff79b1d783b1806f0cee386ae1341efe
7
- data.tar.gz: c7d653609f2e31a773031f302dd12bfbf5a401a90425f77aa395900e73f7e21b7443f840cadb9d7ef970586493d1a9b28469580049ba65c24ca1b8f50ff3ca9a
6
+ metadata.gz: 3c1902bf3f2021a837837a1fad2e8f6d750c10cbd17fb72a2ff2d82162a996f71c21b31b62b9199d55d677fc9a80db10f1cefc5374cbd63fe2c7377ecad1b530
7
+ data.tar.gz: e9c52473e58614613b91f42b5fe6e4e07d4642db85dd50d24bbcd9f319ed77c9d29d21a9e1f5f86bb8153a1de3a7b5bcf9e7b2210e24660bde07edbd9467f27c
data/Readme.md CHANGED
@@ -12,4 +12,9 @@ A simple exponential backoff retry wrapper.
12
12
  ExpRetry.new.call do
13
13
  something_unreliable
14
14
  end
15
+
16
+ ExpRetry.new.call(exception: SpecificError) do
17
+ something_generic # errors will surface immediately
18
+ something_specific # errors will trigger retries
19
+ end
15
20
  ```
data/exp-retry.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'exp_retry'
3
- s.version = '0.0.2'
3
+ s.version = '0.0.3'
4
4
  s.date = '2018-10-16'
5
5
  s.summary = 'Exponential backoff retry'
6
6
  s.description = 'A simple exponential backoff retry wrapper.'
data/lib/exp_retry.rb CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  # Exponential backoff retry wrapper
4
4
  class ExpRetry
5
- def initialize(retries: 3)
5
+ def initialize(retries: 3, exception: StandardError)
6
6
  @retries = retries
7
+ @exception = exception
7
8
  end
8
9
 
9
10
  def call
10
11
  yield if block_given?
11
- rescue StandardError => e
12
+ rescue @exception => e
12
13
  check(e)
13
14
  retry
14
15
  end
@@ -29,4 +29,16 @@ RSpec.describe ExpRetry do
29
29
  ExpRetry.new.call { raise 'Fail forever' }
30
30
  end.to raise_error(RuntimeError, 'Fail forever')
31
31
  end
32
+
33
+ it 'should raise after too many retries with a specified exception class' do
34
+ expect do
35
+ ExpRetry.new(exception: RuntimeError).call { raise 'Fail forever again' }
36
+ end.to raise_error(RuntimeError, 'Fail forever again')
37
+ end
38
+
39
+ it 'should not retry for a non-matching exception class' do
40
+ expect do
41
+ ExpRetry.new(exception: RuntimeError).call { raise ArgumentError }
42
+ end.to raise_error(ArgumentError)
43
+ end
32
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exp_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander