ztk 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/lib/ztk/rescue_retry.rb +7 -0
- data/lib/ztk/version.rb +1 -1
- data/spec/ztk/rescue_retry_spec.rb +13 -0
- data/ztk.gemspec +1 -0
- metadata +20 -4
data/Gemfile
CHANGED
data/lib/ztk/rescue_retry.rb
CHANGED
@@ -114,6 +114,8 @@ module ZTK
|
|
114
114
|
# instead of performing retry on all exceptions.
|
115
115
|
# @option options [Float,Integer] :delay (1) How long to sleep for between
|
116
116
|
# each retry.
|
117
|
+
# @option options [Lambda,Proc] :on_retry (nil) A proc or lambda to call
|
118
|
+
# when we catch an exception and retry.
|
117
119
|
#
|
118
120
|
# @yield Block should execute the tasks to be rescued and retried if
|
119
121
|
# needed.
|
@@ -133,10 +135,15 @@ module ZTK
|
|
133
135
|
rescue options.on => e
|
134
136
|
if ((options.tries -= 1) > 0)
|
135
137
|
options.ui.logger.warn { "Caught #{e.inspect}, we will give it #{options.tries} more tr#{options.tries > 1 ? 'ies' : 'y'}." }
|
138
|
+
|
136
139
|
sleep(options.delay)
|
140
|
+
|
141
|
+
options.on_retry and options.on_retry.call(e)
|
142
|
+
|
137
143
|
retry
|
138
144
|
else
|
139
145
|
options.ui.logger.fatal { "Caught #{e.inspect} and we have no more tries left, sorry, we have to give up now." }
|
146
|
+
|
140
147
|
raise e
|
141
148
|
end
|
142
149
|
end
|
data/lib/ztk/version.rb
CHANGED
@@ -73,6 +73,19 @@ describe ZTK::RescueRetry do
|
|
73
73
|
$counter.should == 1
|
74
74
|
end
|
75
75
|
|
76
|
+
it "should call our lambda when it catches an exception and retries" do
|
77
|
+
$counter = 0
|
78
|
+
on_retry_m = lambda { |exception|
|
79
|
+
$counter +=1
|
80
|
+
}
|
81
|
+
lambda {
|
82
|
+
ZTK::RescueRetry.try(:tries => 3, :on => EOFError, :on_retry => on_retry_m) do
|
83
|
+
raise EOFError
|
84
|
+
end
|
85
|
+
}.should raise_error EOFError
|
86
|
+
$counter.should == 2
|
87
|
+
end
|
88
|
+
|
76
89
|
end
|
77
90
|
|
78
91
|
end
|
data/ztk.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: erubis
|
@@ -155,6 +155,22 @@ dependencies:
|
|
155
155
|
- - ! '>='
|
156
156
|
- !ruby/object:Gem::Version
|
157
157
|
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: coveralls
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
158
174
|
description: Zachary's (DevOp) Tool Kit
|
159
175
|
email:
|
160
176
|
- zachary@jovelabs.com
|
@@ -247,7 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
247
263
|
version: '0'
|
248
264
|
segments:
|
249
265
|
- 0
|
250
|
-
hash: -
|
266
|
+
hash: -568917063704352555
|
251
267
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
252
268
|
none: false
|
253
269
|
requirements:
|
@@ -256,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
256
272
|
version: '0'
|
257
273
|
segments:
|
258
274
|
- 0
|
259
|
-
hash: -
|
275
|
+
hash: -568917063704352555
|
260
276
|
requirements: []
|
261
277
|
rubyforge_project:
|
262
278
|
rubygems_version: 1.8.25
|