exp_retry 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +2 -2
- data/Readme.md +9 -0
- data/exp-retry.gemspec +2 -2
- data/lib/exp_retry.rb +10 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 478f3730c0066f80c4299dfaab7e4da27fd681386e3ffc5bb97b3f9f67717e40
|
4
|
+
data.tar.gz: 78ccc9dbedcb20e4128d3327ae344e5fa2c6eaaf914a5a37ac4e337fc2c907e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ec84ab84ca800bed992be7efdd5e21a7054b3d87f6855fbdd1b11845a755ee72d8cd4a91eaf0a4ce53b9192093697f25e45e6ddf7bf3bdca403167ae27576ff
|
7
|
+
data.tar.gz: d159d8dd4355a4447d50ef5f38f627022f3d25329f3c6d7e9cb71b636b76950d720e050473ac0be18dfede165a6596af58e02b944f38bf804f96949a7426cce8
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -61,3 +61,12 @@ ExpRetry.for(retries: 5, exception: [SpecificError, AnotherError]) do
|
|
61
61
|
something_specific # errors will trigger up to 5 retries
|
62
62
|
end
|
63
63
|
```
|
64
|
+
|
65
|
+
To display internal logging, run with the `verbose` flag:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
ExpRetry.for(retries: 5, exception: SpecificError, verbose: true) do
|
69
|
+
something_generic # errors will surface immediately
|
70
|
+
something_specific # errors will trigger up to 5 retries
|
71
|
+
end
|
72
|
+
```
|
data/exp-retry.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'exp_retry'
|
3
|
-
s.version = '0.0.
|
4
|
-
s.date = '
|
3
|
+
s.version = '0.0.10'
|
4
|
+
s.date = '2019-06-15'
|
5
5
|
s.summary = 'Exponential backoff retry'
|
6
6
|
s.description = 'A simple exponential backoff retry wrapper.'
|
7
7
|
s.homepage = 'http://rubygems.org/gems/exp_retry'
|
data/lib/exp_retry.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
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 }
|
5
|
+
def self.for(retries: 3, exception: StandardError, verbose: false)
|
6
|
+
new(retries: retries, exception: exception, verbose: verbose).call { yield }
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize(retries: 3, exception: StandardError)
|
9
|
+
def initialize(retries: 3, exception: StandardError, verbose: false)
|
10
10
|
@retries = retries
|
11
11
|
@exception = exception
|
12
|
+
@verbose = verbose
|
12
13
|
end
|
13
14
|
|
14
15
|
def call
|
@@ -20,8 +21,8 @@ class ExpRetry
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
def check(
|
24
|
-
retried > @retries ? raise(
|
24
|
+
def check(exception)
|
25
|
+
retried > @retries ? raise(exception) : delay(exception)
|
25
26
|
end
|
26
27
|
|
27
28
|
def retried
|
@@ -29,8 +30,10 @@ class ExpRetry
|
|
29
30
|
@retried += 1
|
30
31
|
end
|
31
32
|
|
32
|
-
def delay(
|
33
|
-
|
33
|
+
def delay(exception)
|
34
|
+
output = "*** #{exception}. Retrying in #{2**@retried} seconds..."
|
35
|
+
output = '-' if @verbose
|
36
|
+
puts output
|
34
37
|
sleep 2**@retried
|
35
38
|
end
|
36
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exp_retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.6
|
111
|
+
rubygems_version: 2.7.6
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Exponential backoff retry
|