retry 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +2 -2
- data/Rakefile +7 -0
- data/lib/retry.rb +8 -2
- data/lib/retry/version.rb +1 -1
- data/website/index.html +20 -11
- data/website/index.txt +17 -9
- metadata +1 -1
data/README.txt
CHANGED
@@ -9,10 +9,10 @@ The Retry gem easily allows you to wrap a block of text in a "retry" so that it
|
|
9
9
|
|
10
10
|
Usage is relatively simple:
|
11
11
|
|
12
|
-
10.tries
|
12
|
+
10.tries do
|
13
13
|
# unreliable code goes here...
|
14
14
|
raise 'network connection failed' if rand() < 0.7
|
15
15
|
puts 'success'
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
For further options, see Fixnum#tries
|
data/Rakefile
CHANGED
@@ -2,12 +2,15 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/clean'
|
4
4
|
require 'rake/testtask'
|
5
|
+
require 'spec/rake/spectask'
|
5
6
|
require 'rake/packagetask'
|
6
7
|
require 'rake/gempackagetask'
|
7
8
|
require 'rake/rdoctask'
|
8
9
|
require 'rake/contrib/rubyforgepublisher'
|
9
10
|
require 'fileutils'
|
10
11
|
require 'hoe'
|
12
|
+
|
13
|
+
|
11
14
|
include FileUtils
|
12
15
|
require File.join(File.dirname(__FILE__), 'lib', 'retry', 'version')
|
13
16
|
|
@@ -91,3 +94,7 @@ task :check_version do
|
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
97
|
+
desc "Run All Specs"
|
98
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
99
|
+
t.spec_files = FileList['spec/**/*.rb']
|
100
|
+
end
|
data/lib/retry.rb
CHANGED
@@ -2,7 +2,12 @@ require 'retry/version'
|
|
2
2
|
|
3
3
|
|
4
4
|
class Fixnum
|
5
|
-
|
5
|
+
|
6
|
+
=begin rdoc
|
7
|
+
- message => allows you to provide some context to the error messages that get printed out.
|
8
|
+
- output_stream => allows you to specify to which output stream you want any errors to be written. Defaults to $stderr
|
9
|
+
=end
|
10
|
+
def tries(message = nil, output_stream = $stderr) # :yields:
|
6
11
|
current_try_num = 1
|
7
12
|
begin
|
8
13
|
yield current_try_num
|
@@ -10,7 +15,8 @@ class Fixnum
|
|
10
15
|
if current_try_num >= self
|
11
16
|
raise
|
12
17
|
else
|
13
|
-
|
18
|
+
m = message ? " (#{message})" : ''
|
19
|
+
output_stream.puts "Try #{current_try_num} failed#{m}: #{e}"
|
14
20
|
current_try_num = current_try_num.next
|
15
21
|
retry
|
16
22
|
end
|
data/lib/retry/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
<link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
|
6
6
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
7
7
|
<title>
|
8
|
-
|
8
|
+
Retry Gem
|
9
9
|
</title>
|
10
10
|
<script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
|
11
11
|
<style>
|
@@ -30,15 +30,15 @@
|
|
30
30
|
<body>
|
31
31
|
<div id="main">
|
32
32
|
|
33
|
-
<h1>
|
33
|
+
<h1>Retry Gem</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/retry"; return false'>
|
35
35
|
Get Version
|
36
|
-
<a href="http://rubyforge.org/projects/retry" class="numbers">0.0.
|
36
|
+
<a href="http://rubyforge.org/projects/retry" class="numbers">0.0.2</a>
|
37
37
|
</div>
|
38
|
-
<
|
38
|
+
<h2>What</h2>
|
39
39
|
|
40
40
|
|
41
|
-
<
|
41
|
+
<p>Benjamin Franklin said, “The definition of insanity is doing the same thing over and over and expecting different results.” Sometimes, though, a retry is exactly what you need. You may need to call something that is not reliable. Maybe it is a network connection that might be down temporarily. How often have you built retry logic around a bit of code that just might fail on occasion? This ruby gem takes care of that situation nicely.</p>
|
42
42
|
|
43
43
|
|
44
44
|
<h2>Installing</h2>
|
@@ -46,20 +46,29 @@
|
|
46
46
|
|
47
47
|
<pre syntax="ruby">sudo gem install retry</pre>
|
48
48
|
|
49
|
-
<h2>The basics</h2>
|
50
|
-
|
51
|
-
|
52
49
|
<h2>Demonstration of usage</h2>
|
53
50
|
|
54
51
|
|
55
|
-
|
52
|
+
<pre syntax="ruby">
|
53
|
+
require 'retry'
|
54
|
+
|
55
|
+
10.tries do
|
56
|
+
raise 'network connection failed' if rand() < 0.7
|
57
|
+
puts 'success'
|
58
|
+
end
|
59
|
+
</pre>
|
56
60
|
|
61
|
+
<p>Output:</p>
|
57
62
|
|
58
|
-
<p><a href="http://groups.google.com/group/retry">http://groups.google.com/group/retry</a></p>
|
59
63
|
|
64
|
+
<pre syntax="ruby">
|
60
65
|
|
61
|
-
|
66
|
+
> ruby tries.rb
|
67
|
+
> Try 1 failed: network connection failed
|
68
|
+
> Try 2 failed: network connection failed
|
69
|
+
> success
|
62
70
|
|
71
|
+
</pre>
|
63
72
|
|
64
73
|
<h2>License</h2>
|
65
74
|
|
data/website/index.txt
CHANGED
@@ -1,27 +1,35 @@
|
|
1
|
-
h1.
|
2
|
-
|
3
|
-
h1. → 'retry'
|
1
|
+
h1. Retry Gem
|
4
2
|
|
5
3
|
|
6
4
|
h2. What
|
7
5
|
|
6
|
+
Benjamin Franklin said, "The definition of insanity is doing the same thing over and over and expecting different results." Sometimes, though, a retry is exactly what you need. You may need to call something that is not reliable. Maybe it is a network connection that might be down temporarily. How often have you built retry logic around a bit of code that just might fail on occasion? This ruby gem takes care of that situation nicely.
|
8
7
|
|
9
8
|
h2. Installing
|
10
9
|
|
11
10
|
<pre syntax="ruby">sudo gem install retry</pre>
|
12
11
|
|
13
|
-
h2. The basics
|
14
|
-
|
15
|
-
|
16
12
|
h2. Demonstration of usage
|
17
13
|
|
14
|
+
<pre syntax="ruby">
|
15
|
+
require 'retry'
|
16
|
+
|
17
|
+
10.tries do
|
18
|
+
raise 'network connection failed' if rand() < 0.7
|
19
|
+
puts 'success'
|
20
|
+
end
|
21
|
+
</pre>
|
18
22
|
|
23
|
+
Output:
|
19
24
|
|
20
|
-
|
25
|
+
<pre syntax="ruby">
|
21
26
|
|
22
|
-
|
27
|
+
> ruby tries.rb
|
28
|
+
> Try 1 failed: network connection failed
|
29
|
+
> Try 2 failed: network connection failed
|
30
|
+
> success
|
23
31
|
|
24
|
-
|
32
|
+
</pre>
|
25
33
|
|
26
34
|
h2. License
|
27
35
|
|