exp_retry 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Readme.md +9 -0
- data/exp-retry.gemspec +1 -1
- data/lib/exp_retry.rb +4 -0
- data/spec/lib/exp_retry_spec.rb +7 -3
- 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: 5936c444eeb797c31e32202090c0f5828dc1de27
|
4
|
+
data.tar.gz: 9d8881e4467bfd72fa97384642de3c5e674202bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc986e4bfbda307a4722fbc448402aa9005fae0f659a45a92b830d451196e9fa001ea9ea780336fb850d57a93012e4ef5a62c094d36e35f8d8242e76950156d
|
7
|
+
data.tar.gz: b44bbc1f2a869fe9fe4de7a10c862bf638338cb647fa3ee949e3e7d757b924f8d36f71b8d945f888bf951a8de992030d8d8fcb8c8ab3a627841d9dedde7bd753
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -52,3 +52,12 @@ ExpRetry.new(retries: 5).call do
|
|
52
52
|
something_unreliable # will retry 5 times
|
53
53
|
end
|
54
54
|
```
|
55
|
+
|
56
|
+
There is also a helper method to simplify calling on a new instance:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
ExpRetry.for(retries: 5, exception: [SpecificError, AnotherError]) do
|
60
|
+
something_generic # errors will surface immediately
|
61
|
+
something_specific # errors will trigger up to 5 retries
|
62
|
+
end
|
63
|
+
```
|
data/exp-retry.gemspec
CHANGED
data/lib/exp_retry.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
# Exponential backoff retry wrapper
|
4
4
|
class ExpRetry
|
5
|
+
def self.for(retries: 3, exception: StandardError)
|
6
|
+
new(retries: retries, exception: exception).call { yield }
|
7
|
+
end
|
8
|
+
|
5
9
|
def initialize(retries: 3, exception: StandardError)
|
6
10
|
@retries = retries
|
7
11
|
@exception = exception
|
data/spec/lib/exp_retry_spec.rb
CHANGED
@@ -4,9 +4,13 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe ExpRetry do
|
6
6
|
it 'should allow normal execution' do
|
7
|
-
r = ExpRetry.new.call
|
8
|
-
|
9
|
-
|
7
|
+
r = ExpRetry.new.call { 'Something' }
|
8
|
+
|
9
|
+
expect(r).to eql('Something')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow normal execution using for' do
|
13
|
+
r = ExpRetry.for { 'Something' }
|
10
14
|
|
11
15
|
expect(r).to eql('Something')
|
12
16
|
end
|