just-retry 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/just-retry.gemspec +2 -1
- data/lib/just/retry/version.rb +1 -1
- data/lib/just/retry.rb +4 -4
- data/spec/retry_spec.rb +70 -0
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c22743aab9c834710d3217c306cb0088e2dc9ce
|
4
|
+
data.tar.gz: 2163b00419075b3ea14889f3e1334fb5a7b44c0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4318cdc6e3797bef27e28c6a6bcd98f7b30a99169fb06f0f15c4eaf1af8eaced9c05c81300e519cca236fea4b2a78c828d9703bdb42fb722c89bb6459ec42824
|
7
|
+
data.tar.gz: 13192123e8fb586bdfacb959d73d43753e3248781fb59c27fefdf865380bab4e071224e02190a7ab64b5ed04fcecdd50a7855c57e4a07d6380ea19f9b9c25941
|
data/README.md
CHANGED
data/just-retry.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Just::Retry::VERSION
|
9
9
|
spec.authors = ["Michael Greenly"]
|
10
10
|
spec.email = ["mgreenly@gmail.com"]
|
11
|
-
spec.description = %q{Provides a counted retry machanism}
|
12
11
|
spec.summary = %q{Provides a counted retry mechansim}
|
12
|
+
spec.description = spec.summary
|
13
13
|
spec.homepage = "https://github.com/mgreenly/just-retry"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
23
24
|
end
|
data/lib/just/retry/version.rb
CHANGED
data/lib/just/retry.rb
CHANGED
@@ -2,12 +2,12 @@ require "just/retry/version"
|
|
2
2
|
|
3
3
|
module Just
|
4
4
|
def retry(opts={})
|
5
|
-
opts = {
|
6
|
-
delay, tries, exception, logger = opts[:delay], opts[:tries], opts[:
|
5
|
+
opts = {delay: 0.0, on: StandardError, tries: 2}.merge(opts)
|
6
|
+
delay, tries, exception, logger = opts[:delay], opts[:tries], opts[:on], opts[:logger]
|
7
7
|
count = 0
|
8
8
|
begin
|
9
9
|
count += 1
|
10
|
-
|
10
|
+
yield
|
11
11
|
rescue exception => e
|
12
12
|
if count < tries
|
13
13
|
if logger
|
@@ -19,7 +19,7 @@ module Just
|
|
19
19
|
end
|
20
20
|
retry
|
21
21
|
else
|
22
|
-
raise
|
22
|
+
raise e
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/spec/retry_spec.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'just/retry'
|
2
|
+
|
3
|
+
describe "Just::retry" do
|
4
|
+
|
5
|
+
it "The block is only called once if it succeeds" do
|
6
|
+
object = Object.new
|
7
|
+
object.should_receive(:ping).once.and_return(:success)
|
8
|
+
expect {
|
9
|
+
Just::retry do
|
10
|
+
object.ping
|
11
|
+
end
|
12
|
+
}.not_to raise_error(Exception)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "The block is called twice by default if it fails" do
|
16
|
+
object = Object.new
|
17
|
+
object.should_receive(:ping).twice { raise StandardError }
|
18
|
+
expect {
|
19
|
+
Just::retry do
|
20
|
+
object.ping
|
21
|
+
end
|
22
|
+
}.to raise_error(StandardError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "The block is called n times when a try count is specified" do
|
26
|
+
object = Object.new
|
27
|
+
n = 5
|
28
|
+
object.should_receive(:ping).exactly(n).times { raise StandardError }
|
29
|
+
expect {
|
30
|
+
Just::retry tries: n do
|
31
|
+
object.ping
|
32
|
+
end
|
33
|
+
}.to raise_error(StandardError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "Unexpected exceptions are reraised" do
|
37
|
+
object = Object.new
|
38
|
+
object.should_receive(:ping).once { raise StandardError }
|
39
|
+
expect {
|
40
|
+
Just::retry on: IOError do
|
41
|
+
object.ping
|
42
|
+
end
|
43
|
+
}.to raise_error(StandardError)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sleep is called if it's provided" do
|
47
|
+
object = Object.new
|
48
|
+
object.should_receive(:ping).twice { raise StandardError }
|
49
|
+
Just.stub!(:sleep)
|
50
|
+
Just.should_receive(:sleep).once.with(30)
|
51
|
+
expect {
|
52
|
+
Just::retry delay: 30 do
|
53
|
+
object.ping
|
54
|
+
end
|
55
|
+
}.to raise_error(StandardError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "the retry is logged if a log is provided" do
|
59
|
+
object = Object.new
|
60
|
+
object.should_receive(:ping).twice { raise StandardError }
|
61
|
+
logger = Object.new
|
62
|
+
logger.should_receive(:error).with(any_args)
|
63
|
+
logger.should_receive(:debug).with(any_args)
|
64
|
+
expect {
|
65
|
+
Just::retry logger: logger do
|
66
|
+
object.ping
|
67
|
+
end
|
68
|
+
}.to raise_error(StandardError)
|
69
|
+
end
|
70
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just-retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Greenly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,21 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Provides a counted retry mechansim
|
42
56
|
email:
|
43
57
|
- mgreenly@gmail.com
|
44
58
|
executables: []
|
@@ -53,6 +67,7 @@ files:
|
|
53
67
|
- just-retry.gemspec
|
54
68
|
- lib/just/retry.rb
|
55
69
|
- lib/just/retry/version.rb
|
70
|
+
- spec/retry_spec.rb
|
56
71
|
homepage: https://github.com/mgreenly/just-retry
|
57
72
|
licenses:
|
58
73
|
- MIT
|
@@ -77,4 +92,5 @@ rubygems_version: 2.0.3
|
|
77
92
|
signing_key:
|
78
93
|
specification_version: 4
|
79
94
|
summary: Provides a counted retry mechansim
|
80
|
-
test_files:
|
95
|
+
test_files:
|
96
|
+
- spec/retry_spec.rb
|