try_again 1.0.0 → 2.0.0
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 +7 -0
- data/README +3 -0
- data/lib/try_again.rb +13 -15
- metadata +27 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f543d0fe4fdeaefbdd2a0a9ddc2a36b9ec20c062
|
4
|
+
data.tar.gz: a3c2572280de7f2eb06eb02a16a7fdf74aee9b02
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e873a8df0938b8f635f9970c79c31b2a9d33eb4a92030fb3f1be301930ef501de25db37ac252a1cf5b03397606d3ef007764230adf0a9a2868ba51967afe54f
|
7
|
+
data.tar.gz: ddfae4232b83ca05acf5c3a5c1ab932eee37b4c577b064be51bb6b1c82330340710e392e1cb43dfecf95883f7061a53959d90feb3b3c10dd5f8c0998fdd977a4
|
data/README
CHANGED
data/lib/try_again.rb
CHANGED
@@ -1,34 +1,32 @@
|
|
1
|
-
#@version
|
1
|
+
#@version 2
|
2
2
|
#@author Arthur
|
3
3
|
module TryAgain
|
4
4
|
#@param options [Hash] (:sleep => number, :attempts => number, :error => Error, :kill => boolean)
|
5
5
|
#@param block [Block] block of code to be attempted
|
6
6
|
#@return [Boolean]
|
7
|
-
def self.retry(
|
8
|
-
|
9
|
-
options = defaults.merge options
|
10
|
-
out = options[:output]
|
7
|
+
def self.retry( sleep: 3, attempts: 3, error: StandardError, kill: false, output: nil, &block )
|
8
|
+
out = output
|
11
9
|
if out and !out.is_a? IO
|
12
10
|
raise InvalidOutput
|
13
11
|
end
|
14
|
-
|
15
|
-
failed
|
12
|
+
attempted = 0
|
13
|
+
failed = false
|
16
14
|
|
17
15
|
begin
|
18
16
|
yield
|
19
|
-
rescue
|
20
|
-
|
21
|
-
out.puts "#{
|
22
|
-
if
|
23
|
-
sleep
|
17
|
+
rescue error => e
|
18
|
+
attempted += 1
|
19
|
+
out.puts "#{ error.to_s } for the #{attempts}# attempt" if out
|
20
|
+
if attempted < attempts
|
21
|
+
sleep sleep
|
24
22
|
retry
|
25
23
|
end
|
26
|
-
out.puts "#Giving up on #{
|
27
|
-
raise
|
24
|
+
out.puts "#Giving up on #{ error.to_s }, too many attempts" if out
|
25
|
+
raise e if kill
|
28
26
|
failed = true
|
29
27
|
end
|
30
28
|
if !failed and out
|
31
|
-
out.puts "#{
|
29
|
+
out.puts "#{ error.to_s } took #{attempts + 1} attempts to pass"
|
32
30
|
end
|
33
31
|
return !failed
|
34
32
|
end
|
metadata
CHANGED
@@ -1,56 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: try_again
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
6
|
+
authors:
|
7
|
+
- Arthur Silva
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2012-09-03 00:00:00 Z
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
14
12
|
dependencies: []
|
15
|
-
|
16
|
-
|
13
|
+
description: " This method is usefull for when you want to attempt to get a resource
|
14
|
+
on a network and it may fail \n\n Or maybe you know that there's a possibility
|
15
|
+
that the databases haven't sync yet and you want to try a few times till they do\n"
|
17
16
|
email: awls99@gmail.com
|
18
17
|
executables: []
|
19
|
-
|
20
18
|
extensions: []
|
21
|
-
|
22
19
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
- README
|
20
|
+
files:
|
21
|
+
- lib/try_again.rb
|
22
|
+
- README
|
27
23
|
homepage: https://github.com/awls99/Try-Again
|
28
24
|
licenses: []
|
29
|
-
|
25
|
+
metadata: {}
|
30
26
|
post_install_message:
|
31
27
|
rdoc_options: []
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: "0"
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
47
40
|
requirements: []
|
48
|
-
|
49
41
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.
|
42
|
+
rubygems_version: 2.1.11
|
51
43
|
signing_key:
|
52
|
-
specification_version:
|
44
|
+
specification_version: 4
|
53
45
|
summary: A helping method to to retry a block a few times with a sleep in between
|
54
46
|
test_files: []
|
55
|
-
|
56
|
-
has_rdoc:
|