def_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 +4 -4
- data/README.md +1 -1
- data/Rakefile +3 -0
- data/lib/def_retry/retrier.rb +9 -5
- data/lib/def_retry/version.rb +1 -1
- data/lib/def_retry.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d35fdb197f95fa60911086e999f70e25d327c6c9
|
4
|
+
data.tar.gz: fa7195d2881db3c9ff1a392d771166ea4731ed68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd716852f0c4ed1db2d49827c2eb5b06579270d09bf51d6a7433f58f786c516fa503e4898677fb6014e338146203e8d45d9c91809e5bf1efa864c8738a2a4127
|
7
|
+
data.tar.gz: acca16ef89d89f276093c66d158f05f1c142684adbf433fbe84bb87d75433659da79a1c4976d77fef14e55dc58dbfadb3e00ebd411b72fb2aef6ef09aea3f52f
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/def_retry/retrier.rb
CHANGED
@@ -7,11 +7,11 @@ module DefRetry
|
|
7
7
|
exponential: ->(n) { n**2 }
|
8
8
|
}
|
9
9
|
|
10
|
-
def initialize(options
|
11
|
-
@block = block
|
10
|
+
def initialize(options)
|
12
11
|
@tries = options.fetch :tries, DEFAULT_TRIES
|
13
12
|
@on_retry = options.fetch :on_retry, ->(e, n) {}
|
14
13
|
@on_ensure = options.fetch :on_ensure, ->(r, n) {}
|
14
|
+
@re_raise = options.fetch :re_raise, true
|
15
15
|
@sleep = options.fetch :sleep, false
|
16
16
|
|
17
17
|
begin
|
@@ -27,18 +27,22 @@ module DefRetry
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def run
|
30
|
+
def run(&block)
|
31
31
|
@try_count = 0
|
32
32
|
@return = nil
|
33
33
|
|
34
34
|
begin
|
35
|
-
@return =
|
35
|
+
@return = block.call
|
36
36
|
rescue *@exceptions => e
|
37
37
|
@try_count += 1
|
38
38
|
sleep @sleep.call(@try_count) if @sleep
|
39
39
|
@on_retry.call e, @try_count
|
40
40
|
|
41
|
-
|
41
|
+
if @try_count < @tries
|
42
|
+
retry
|
43
|
+
elsif @re_raise
|
44
|
+
raise e
|
45
|
+
end
|
42
46
|
ensure
|
43
47
|
@on_ensure.call @return, @try_count
|
44
48
|
@return
|
data/lib/def_retry/version.rb
CHANGED
data/lib/def_retry.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: def_retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Salazar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|