exp_retry 0.0.2 → 0.0.3
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/Readme.md +5 -0
- data/exp-retry.gemspec +1 -1
- data/lib/exp_retry.rb +3 -2
- data/spec/lib/exp_retry_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea9f2d770247bb54f9924524a61fc134c642bfb9
|
4
|
+
data.tar.gz: 93e6e3ca775f7dc85cab22bb928c7adda4370020
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
12
|
+
rescue @exception => e
|
12
13
|
check(e)
|
13
14
|
retry
|
14
15
|
end
|
data/spec/lib/exp_retry_spec.rb
CHANGED
@@ -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
|