retry 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/retry.rb +16 -3
- data/lib/retry/version.rb +2 -2
- data/website/index.html +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/lib/retry.rb
CHANGED
@@ -5,9 +5,11 @@ class Fixnum
|
|
5
5
|
|
6
6
|
=begin rdoc
|
7
7
|
- message => allows you to provide some context to the error messages that get printed out.
|
8
|
-
- output_stream =>
|
8
|
+
- output_stream => allows you to specify to which output stream you want any errors to be written. Defaults to $stderr
|
9
|
+
- backoff => specify a backoff strategy. Currently this is an array of timeouts, probably escalating like [1,2,4,8]. The array can be as short as you like. In the previous example if you had ten tries it would just continue to use '8' as the timeout value once it reached the end of the array.
|
9
10
|
=end
|
10
|
-
def tries(message = nil, output_stream = $stderr) # :yields:
|
11
|
+
def tries(message = nil, output_stream = $stderr, backoff_times = []) # :yields:
|
12
|
+
output_stream ||= $stderr # if they pass in nill, still default.
|
11
13
|
current_try_num = 1
|
12
14
|
begin
|
13
15
|
yield current_try_num
|
@@ -15,11 +17,22 @@ class Fixnum
|
|
15
17
|
if current_try_num >= self
|
16
18
|
raise
|
17
19
|
else
|
20
|
+
# backoff strategy
|
21
|
+
if backoff_times && backoff_times.respond_to?(:shift) && !backoff_times.empty?
|
22
|
+
@backoff_sleep = backoff_times.shift
|
23
|
+
end
|
24
|
+
Kernel.sleep(@backoff_sleep) if @backoff_sleep
|
25
|
+
|
26
|
+
# user messaging
|
18
27
|
m = message ? " (#{message})" : ''
|
19
|
-
|
28
|
+
s = @backoff_sleep ? ", sleeping for #{@backoff_sleep} seconds" : ''
|
29
|
+
output_stream.puts "Try #{current_try_num} failed#{m}#{s}: #{e}"
|
30
|
+
|
31
|
+
# actual retry code
|
20
32
|
current_try_num = current_try_num.next
|
21
33
|
retry
|
22
34
|
end
|
23
35
|
end
|
24
36
|
end
|
37
|
+
|
25
38
|
end
|
data/lib/retry/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
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.1.0</a>
|
37
37
|
</div>
|
38
38
|
<h2>What</h2>
|
39
39
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: retry
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-06-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-06-15 00:00:00 +01:00
|
8
8
|
summary: easily retry blocks of code
|
9
9
|
require_paths:
|
10
10
|
- lib
|