attempt 0.1.2 → 0.2.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.
- data/CHANGES +8 -0
- data/Rakefile +23 -0
- data/attempt.gemspec +28 -0
- data/lib/attempt.rb +17 -2
- data/test/test_attempt.rb +3 -1
- metadata +18 -6
data/CHANGES
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 0.2.0 - 26-Sep-2009
|
2
|
+
* Now requires and uses the structured_warnings gem. If a block of code fails
|
3
|
+
prior to reaching the maximum number of tries, and warnings are on, then
|
4
|
+
an Attempt::Warning is raised.
|
5
|
+
* Fixed a packaging bug.
|
6
|
+
* Refactored the attempt.gemspec file a bit.
|
7
|
+
* Added the 'gem' task to the Rakefile.
|
8
|
+
|
1
9
|
== 0.1.2 - 1-Aug-2009
|
2
10
|
* License changed to Artistic 2.0.
|
3
11
|
* Added test-unit as a development dependency.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc "Install the attempt library (non-gem)"
|
5
|
+
task :install do
|
6
|
+
cp 'lib/attempt.rb', Config::CONFIG['sitelibdir'], :verbose => true
|
7
|
+
end
|
8
|
+
|
9
|
+
desc 'Build the gem'
|
10
|
+
task :gem do
|
11
|
+
spec = eval(IO.read('attempt.gemspec'))
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
|
14
|
+
desc "Install the attempt library as a gem"
|
15
|
+
task :install_gem => [:gem] do
|
16
|
+
file = Dir["*.gem"].first
|
17
|
+
sh "gem install #{file}"
|
18
|
+
end
|
19
|
+
|
20
|
+
Rake::TestTask.new do |t|
|
21
|
+
t.warning = true
|
22
|
+
t.verbose = true
|
23
|
+
end
|
data/attempt.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'attempt'
|
5
|
+
gem.version = '0.2.0'
|
6
|
+
gem.author = 'Daniel J. Berger'
|
7
|
+
gem.license = 'Artistic 2.0'
|
8
|
+
gem.email = 'djberg96@gmail.com'
|
9
|
+
gem.homepage = 'http://www.rubyforge.org/projects/shards'
|
10
|
+
gem.summary = 'A thin wrapper for begin + rescue + sleep + retry'
|
11
|
+
gem.test_file = 'test/test_attempt.rb'
|
12
|
+
gem.has_rdoc = true
|
13
|
+
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
14
|
+
|
15
|
+
gem.extra_rdoc_files = ['README','CHANGES','MANIFEST']
|
16
|
+
gem.rubyforge_project = 'shards'
|
17
|
+
|
18
|
+
gem.add_dependency('structured_warnings')
|
19
|
+
gem.add_development_dependency('test-unit', '>= 2.0.3')
|
20
|
+
|
21
|
+
gem.description = <<-EOF
|
22
|
+
The attempt library provides a thin wrapper for the typical
|
23
|
+
begin/rescue/sleep/retry dance. Use this in order to robustly
|
24
|
+
handle blocks of code that could briefly flake out, such as a socket
|
25
|
+
or database connection, where it's often better to try again after
|
26
|
+
a brief period rather than fail immediately.
|
27
|
+
EOF
|
28
|
+
end
|
data/lib/attempt.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
1
|
require 'timeout'
|
2
|
+
require 'structured_warnings'
|
2
3
|
|
4
|
+
# The Attempt class encapsulates methods related to multiple attempts at
|
5
|
+
# running the same method before actually failing.
|
3
6
|
class Attempt
|
4
|
-
|
7
|
+
|
8
|
+
# The version of the attempt library.
|
9
|
+
VERSION = '0.2.0'
|
10
|
+
|
11
|
+
# Warning raised if an attempt fails before the maximum number of tries
|
12
|
+
# has been reached.
|
13
|
+
class Warning < StandardWarning; end
|
5
14
|
|
6
15
|
# Number of attempts to make before failing. The default is 3.
|
7
16
|
attr_accessor :tries
|
@@ -46,6 +55,12 @@ class Attempt
|
|
46
55
|
yield self if block_given?
|
47
56
|
end
|
48
57
|
|
58
|
+
# Attempt to perform the operation in the provided block up to +tries+
|
59
|
+
# times, sleeping +interval+ between each try.
|
60
|
+
#
|
61
|
+
# You will not typically use this method directly, but the Kernel#attempt
|
62
|
+
# method instead.
|
63
|
+
#
|
49
64
|
def attempt
|
50
65
|
count = 1
|
51
66
|
begin
|
@@ -59,7 +74,7 @@ class Attempt
|
|
59
74
|
if @tries > 0
|
60
75
|
msg = "Error on attempt # #{count}: #{error}; retrying"
|
61
76
|
count += 1
|
62
|
-
warn msg if @warnings
|
77
|
+
warn Warning, msg if @warnings
|
63
78
|
@log.puts msg if @log
|
64
79
|
@interval += @increment if @increment
|
65
80
|
sleep @interval
|
data/test/test_attempt.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
#
|
4
4
|
# Test case for the attempt library. You should run this test case
|
5
5
|
# via the 'rake test' Rakefile task.
|
6
|
+
#
|
7
|
+
# TODO: Test that an Attempt::Warning is raised.
|
6
8
|
#####################################################################
|
7
9
|
require 'rubygems'
|
8
10
|
gem 'test-unit'
|
@@ -23,7 +25,7 @@ class TC_Attempt < Test::Unit::TestCase
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def test_version
|
26
|
-
assert_equal('0.
|
28
|
+
assert_equal('0.2.0', Attempt::VERSION)
|
27
29
|
end
|
28
30
|
|
29
31
|
def test_attempt_basic
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attempt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
@@ -9,9 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-26 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: structured_warnings
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
15
25
|
- !ruby/object:Gem::Dependency
|
16
26
|
name: test-unit
|
17
27
|
type: :development
|
@@ -22,7 +32,7 @@ dependencies:
|
|
22
32
|
- !ruby/object:Gem::Version
|
23
33
|
version: 2.0.3
|
24
34
|
version:
|
25
|
-
description: " The attempt library provides a thin wrapper for the typical\n begin/rescue/sleep/retry dance.
|
35
|
+
description: " The attempt library provides a thin wrapper for the typical\n begin/rescue/sleep/retry dance. Use this in order to robustly\n handle blocks of code that could briefly flake out, such as a socket\n or database connection, where it's often better to try again after\n a brief period rather than fail immediately.\n"
|
26
36
|
email: djberg96@gmail.com
|
27
37
|
executables: []
|
28
38
|
|
@@ -33,11 +43,13 @@ extra_rdoc_files:
|
|
33
43
|
- CHANGES
|
34
44
|
- MANIFEST
|
35
45
|
files:
|
36
|
-
-
|
37
|
-
- test/test_attempt.rb
|
38
|
-
- README
|
46
|
+
- attempt.gemspec
|
39
47
|
- CHANGES
|
48
|
+
- lib/attempt.rb
|
40
49
|
- MANIFEST
|
50
|
+
- Rakefile
|
51
|
+
- README
|
52
|
+
- test/test_attempt.rb
|
41
53
|
has_rdoc: true
|
42
54
|
homepage: http://www.rubyforge.org/projects/shards
|
43
55
|
licenses:
|