retry 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ +++ 0.1.0 2007-06-15
2
+
3
+ + 1 minor enhancement:
4
+ + Now supports a timed backoff strategy.
5
+
1
6
  +++ 0.0.1 2007-05-31
2
7
 
3
8
  + 1 major enhancement:
@@ -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 => allows you to specify to which output stream you want any errors to be written. Defaults to $stderr
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
- output_stream.puts "Try #{current_try_num} failed#{m}: #{e}"
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
@@ -1,8 +1,8 @@
1
1
  module Retry #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 2
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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.2</a>
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.2
7
- date: 2007-06-01 00:00:00 +01:00
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