try_again 2.0.0 → 2.0.1
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 +7 -2
- data/lib/try_again.rb +5 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2dacba823977338da8aba37543f4c4ed0dd754
|
4
|
+
data.tar.gz: a89790e84b3ce0d48d4209f812a9c2842ce33b7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be11f176f915169aa9f5a8b9d94fc60bfc9c6af8fd89a2fb092e3e1a41576989920b8f53098c1ea0da05417da7ad733e4e426c96b74add664420252261386ca
|
7
|
+
data.tar.gz: 00dd4f7ad51523e47ed31588bd3dd3f04a30149d7d5e23c190f418ea2bcb3f6c2dba04a8f0a34047471e12bac911f91121e8d7499bc74493a3c8e1358f539365
|
data/README
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
##New in version 2.0.0##
|
2
|
+
This version is incompatible with ruby < 2.x
|
3
|
+
Also, if kill == true, it preserves the original error to show you what really went wrong
|
4
|
+
#####
|
5
|
+
|
1
6
|
This method is usefull for when you want to attempt to get a resource on a network and it may fail.
|
2
7
|
Or maybe you know that there's a possibility that the databases haven't sync yet and you want to try a few times till they do.
|
3
8
|
|
@@ -19,7 +24,7 @@ You have a few options that you can pass:
|
|
19
24
|
:attempts => (int) number of times to try run block till give up; defaults 3
|
20
25
|
:sleep => (int) seconds between each attempt; defaults 3
|
21
26
|
:error => (Constant) error to listen to; defaults StandardError
|
22
|
-
:output =>
|
27
|
+
:output => Debug mode, but you can send anything that responds to :puts and you'll get debug info there; defaults nil
|
23
28
|
:kill => (Boolean) If true after the last attempt it will raise your error back to you; defaults false
|
24
29
|
|
25
30
|
You pass them as an hash like so:
|
@@ -28,4 +33,4 @@ TryAgain.retry(:error => MyCustomErrorClass) do
|
|
28
33
|
raise MyCustomErrorClass if something
|
29
34
|
end
|
30
35
|
|
31
|
-
Finally, if :kill => false
|
36
|
+
Finally, if :kill => false TryAgain.retry returns a Boolean telling you whatever there was an error or not.
|
data/lib/try_again.rb
CHANGED
@@ -5,8 +5,10 @@ module TryAgain
|
|
5
5
|
#@param block [Block] block of code to be attempted
|
6
6
|
#@return [Boolean]
|
7
7
|
def self.retry( sleep: 3, attempts: 3, error: StandardError, kill: false, output: nil, &block )
|
8
|
+
tries||=0
|
9
|
+
tries+=1
|
8
10
|
out = output
|
9
|
-
if out and !out.
|
11
|
+
if out and !out.respond_to? :puts
|
10
12
|
raise InvalidOutput
|
11
13
|
end
|
12
14
|
attempted = 0
|
@@ -16,7 +18,7 @@ module TryAgain
|
|
16
18
|
yield
|
17
19
|
rescue error => e
|
18
20
|
attempted += 1
|
19
|
-
out.puts "#{ error.to_s } for the #{
|
21
|
+
out.puts "#{ error.to_s } for the #{tries}# attempt" if out
|
20
22
|
if attempted < attempts
|
21
23
|
sleep sleep
|
22
24
|
retry
|
@@ -26,7 +28,7 @@ module TryAgain
|
|
26
28
|
failed = true
|
27
29
|
end
|
28
30
|
if !failed and out
|
29
|
-
out.puts "#{ error.to_s } took #{
|
31
|
+
out.puts "#{ error.to_s } took #{tries} attempts to pass"
|
30
32
|
end
|
31
33
|
return !failed
|
32
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: try_again
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " This method is usefull for when you want to attempt to get a resource
|
14
14
|
on a network and it may fail \n\n Or maybe you know that there's a possibility
|
@@ -18,10 +18,11 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- lib/try_again.rb
|
22
21
|
- README
|
22
|
+
- lib/try_again.rb
|
23
23
|
homepage: https://github.com/awls99/Try-Again
|
24
|
-
licenses:
|
24
|
+
licenses:
|
25
|
+
- MIT
|
25
26
|
metadata: {}
|
26
27
|
post_install_message:
|
27
28
|
rdoc_options: []
|
@@ -39,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
40
|
version: '0'
|
40
41
|
requirements: []
|
41
42
|
rubyforge_project:
|
42
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.2.2
|
43
44
|
signing_key:
|
44
45
|
specification_version: 4
|
45
46
|
summary: A helping method to to retry a block a few times with a sleep in between
|