ztk 1.6.20 → 1.6.21
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/Gemfile +5 -1
- data/lib/ztk/rescue_retry.rb +17 -6
- data/lib/ztk/ssh/bootstrap.rb +1 -1
- data/lib/ztk/ssh/core.rb +12 -4
- data/lib/ztk/ssh/download.rb +1 -1
- data/lib/ztk/ssh/exec.rb +2 -2
- data/lib/ztk/ssh/file.rb +1 -1
- data/lib/ztk/ssh/upload.rb +1 -1
- data/lib/ztk/version.rb +1 -1
- data/spec/ztk/rescue_retry_spec.rb +14 -1
- metadata +4 -4
data/Gemfile
CHANGED
data/lib/ztk/rescue_retry.rb
CHANGED
@@ -88,10 +88,13 @@ module ZTK
|
|
88
88
|
# optionally set this to 0, but this is generally a bad idea.
|
89
89
|
#
|
90
90
|
# @param [Hash] options Configuration options hash.
|
91
|
-
# @option options [
|
91
|
+
# @option options [Integer] :tries (1) How many attempts at executing the
|
92
92
|
# block before we give up and surface the *Exception*.
|
93
|
-
# @option options [
|
94
|
-
# instead of performing retry on all exceptions.
|
93
|
+
# @option options [Exception,Array<Exception>] :on (Exception) Watch for
|
94
|
+
# specific exceptions instead of performing retry on all exceptions.
|
95
|
+
# @option options [Exception,Array<Exception>] :raise (Exception) Watch
|
96
|
+
# for specific exceptions and do not attempt to retry if they are
|
97
|
+
# raised.
|
95
98
|
# @option options [Float,Integer] :delay (1) How long to sleep for between
|
96
99
|
# each retry.
|
97
100
|
# @option options [Lambda,Proc] :on_retry (nil) A proc or lambda to call
|
@@ -104,16 +107,24 @@ module ZTK
|
|
104
107
|
options = Base.build_config({
|
105
108
|
:tries => 1,
|
106
109
|
:on => Exception,
|
107
|
-
:delay => 1
|
110
|
+
:delay => 1,
|
111
|
+
:raise => nil
|
108
112
|
}.merge(options))
|
109
113
|
options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
|
110
114
|
|
111
115
|
!block_given? and Base.log_and_raise(options.ui.logger, RescueRetryError, "You must supply a block!")
|
112
116
|
|
117
|
+
raise_exceptions = [options.raise].flatten.compact
|
118
|
+
retry_exceptions = [options.on].flatten.compact
|
119
|
+
|
113
120
|
begin
|
114
121
|
return block.call
|
115
|
-
|
116
|
-
|
122
|
+
|
123
|
+
rescue *retry_exceptions => e
|
124
|
+
|
125
|
+
options.tries -= 1
|
126
|
+
|
127
|
+
if ((options.tries > 0) && !raise_exceptions.include?(e.class))
|
117
128
|
options.ui.logger.warn { "Caught #{e.inspect}, we will give it #{options.tries} more tr#{options.tries > 1 ? 'ies' : 'y'}." }
|
118
129
|
|
119
130
|
sleep(options.delay)
|
data/lib/ztk/ssh/bootstrap.rb
CHANGED
@@ -46,7 +46,7 @@ module ZTK
|
|
46
46
|
|
47
47
|
result = nil
|
48
48
|
|
49
|
-
ZTK::RescueRetry.try(:tries => 3, :on_retry => method(:on_retry)) do
|
49
|
+
ZTK::RescueRetry.try(:ui => config.ui, :tries => 3, :on_retry => method(:on_retry)) do
|
50
50
|
self.upload(local_tempfile.path, remote_tempfile)
|
51
51
|
|
52
52
|
result = self.exec(command, options)
|
data/lib/ztk/ssh/core.rb
CHANGED
@@ -15,20 +15,28 @@ module ZTK
|
|
15
15
|
#
|
16
16
|
# Primarily used internally.
|
17
17
|
def sftp
|
18
|
-
@sftp ||=
|
18
|
+
@sftp ||= self.ssh.sftp
|
19
19
|
end
|
20
20
|
|
21
21
|
# Close our session gracefully.
|
22
22
|
def close
|
23
23
|
config.ui.logger.debug { "close" }
|
24
|
-
|
24
|
+
|
25
|
+
if (ssh && !ssh.closed?)
|
26
|
+
ssh.close
|
27
|
+
end
|
28
|
+
|
29
|
+
@ssh = nil
|
30
|
+
@sftp = nil
|
31
|
+
|
32
|
+
true
|
25
33
|
end
|
26
34
|
|
27
35
|
# The on_retry method we'll use with the RescueRetry class.
|
28
36
|
def on_retry(exception)
|
37
|
+
config.ui.logger.warn { "ZTK::SSH on_retry triggered!" }
|
38
|
+
|
29
39
|
close
|
30
|
-
@ssh = nil
|
31
|
-
@sftp = nil
|
32
40
|
end
|
33
41
|
|
34
42
|
end
|
data/lib/ztk/ssh/download.rb
CHANGED
@@ -32,7 +32,7 @@ module ZTK
|
|
32
32
|
options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
|
33
33
|
options.ui.logger.info { "download(#{remote.inspect}, #{local.inspect})" }
|
34
34
|
|
35
|
-
ZTK::RescueRetry.try(:
|
35
|
+
ZTK::RescueRetry.try(:ui => config.ui, :tries => 3, :on_retry => method(:on_retry)) do
|
36
36
|
sftp.download!(remote.to_s, local.to_s, options.send(:table)) do |event, downloader, *args|
|
37
37
|
case event
|
38
38
|
when :open
|
data/lib/ztk/ssh/exec.rb
CHANGED
@@ -47,8 +47,8 @@ module ZTK
|
|
47
47
|
stderr_header = false
|
48
48
|
|
49
49
|
begin
|
50
|
-
|
51
|
-
|
50
|
+
ZTK::RescueRetry.try(:ui => config.ui, :tries => 3, :raise => Timeout::Error, :on_retry => method(:on_retry)) do
|
51
|
+
Timeout.timeout(options.timeout) do
|
52
52
|
|
53
53
|
channel = ssh.open_channel do |chan|
|
54
54
|
options.ui.logger.debug { "Channel opened." }
|
data/lib/ztk/ssh/file.rb
CHANGED
@@ -36,7 +36,7 @@ module ZTK
|
|
36
36
|
!block.nil? and block.call(local_tempfile)
|
37
37
|
local_tempfile.respond_to?(:flush) and local_tempfile.flush
|
38
38
|
|
39
|
-
ZTK::RescueRetry.try(:tries => 3, :on_retry => method(:on_retry)) do
|
39
|
+
ZTK::RescueRetry.try(:ui => config.ui, :tries => 3, :on_retry => method(:on_retry)) do
|
40
40
|
self.upload(local_tempfile.path, remote_tempfile)
|
41
41
|
|
42
42
|
self.exec(%(sudo mv -fv #{remote_tempfile} #{target}), :silence => true)
|
data/lib/ztk/ssh/upload.rb
CHANGED
@@ -27,7 +27,7 @@ module ZTK
|
|
27
27
|
options.ui.logger.debug { "options=#{options.send(:table).inspect}" }
|
28
28
|
config.ui.logger.info { "upload(#{local.inspect}, #{remote.inspect})" }
|
29
29
|
|
30
|
-
ZTK::RescueRetry.try(:
|
30
|
+
ZTK::RescueRetry.try(:ui => config.ui, :tries => 3, :on_retry => method(:on_retry)) do
|
31
31
|
sftp.upload!(local.to_s, remote.to_s) do |event, uploader, *args|
|
32
32
|
case event
|
33
33
|
when :open
|
data/lib/ztk/version.rb
CHANGED
@@ -76,7 +76,7 @@ describe ZTK::RescueRetry do
|
|
76
76
|
it "should call our lambda when it catches an exception and retries" do
|
77
77
|
$counter = 0
|
78
78
|
on_retry_m = lambda { |exception|
|
79
|
-
$counter +=1
|
79
|
+
$counter += 1
|
80
80
|
}
|
81
81
|
lambda {
|
82
82
|
ZTK::RescueRetry.try(:tries => 3, :on => EOFError, :on_retry => on_retry_m) do
|
@@ -86,6 +86,19 @@ describe ZTK::RescueRetry do
|
|
86
86
|
$counter.should == 2
|
87
87
|
end
|
88
88
|
|
89
|
+
it "should not retry exceptions that are ignored" do
|
90
|
+
$counter = 0
|
91
|
+
|
92
|
+
lambda {
|
93
|
+
ZTK::RescueRetry.try(:tries => 3, :raise => EOFError) do
|
94
|
+
$counter += 1
|
95
|
+
raise EOFError
|
96
|
+
end
|
97
|
+
}.should raise_error EOFError
|
98
|
+
|
99
|
+
$counter.should == 1
|
100
|
+
end
|
101
|
+
|
89
102
|
end
|
90
103
|
|
91
104
|
end
|
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.6.
|
4
|
+
version: 1.6.21
|
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-07-
|
12
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -275,7 +275,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
275
|
version: '0'
|
276
276
|
segments:
|
277
277
|
- 0
|
278
|
-
hash:
|
278
|
+
hash: -3636631208901024067
|
279
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
280
|
none: false
|
281
281
|
requirements:
|
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
version: '0'
|
285
285
|
segments:
|
286
286
|
- 0
|
287
|
-
hash:
|
287
|
+
hash: -3636631208901024067
|
288
288
|
requirements: []
|
289
289
|
rubyforge_project:
|
290
290
|
rubygems_version: 1.8.25
|