dtk-action-agent 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/command.rb +89 -6
- data/lib/dtk-action-agent/version.rb +1 -1
- data/lib/position.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5789ee64fd987ef9f0ad70e04cb6b1022bab5189
|
4
|
+
data.tar.gz: b67bce545ec9ea72603ddc4b1ea53a54eafe248b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa34c66700cc5b7d5d385062cc7d617f068aafe8a1e64c36638415286e62d4828e9e982929a4e0323dffe28dd290d66d6228e9cc6fda8566cbb5108e12a06ef9
|
7
|
+
data.tar.gz: 08a7c4184e8e0c9d9184876715e4facfa9e4e5fbdaea905a2e367fa31ee4b0ddf7d0aae35349d69ef308905b3da8cab6c4d7120b896519bc4e6717c884c20c6b
|
data/lib/command.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'open3'
|
2
2
|
require 'timeout'
|
3
3
|
|
4
|
+
|
5
|
+
|
4
6
|
module DTK
|
5
7
|
module Agent
|
6
8
|
|
7
9
|
##
|
8
10
|
# This is container for command as received from Node Agent
|
11
|
+
#
|
9
12
|
|
10
13
|
class Command
|
11
14
|
|
@@ -20,6 +23,7 @@ module DTK
|
|
20
23
|
#
|
21
24
|
|
22
25
|
STDOUT_REDIRECT = ' 2>&1'
|
26
|
+
STREAM_TIMEOUT = 5
|
23
27
|
|
24
28
|
def initialize(value_hash)
|
25
29
|
@command_type = value_hash['type']
|
@@ -45,13 +49,15 @@ module DTK
|
|
45
49
|
begin
|
46
50
|
Commander.set_environment_variables(@env_vars)
|
47
51
|
|
48
|
-
Timeout.timeout(@timeout) do
|
49
|
-
Log.debug("Command started: '#{self.to_s}'")
|
50
|
-
@out, @err, @process_status = Open3.capture3(formulate_command)
|
51
|
-
end
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
results = capture3_with_timeout(formulate_command)
|
54
|
+
|
55
|
+
@out = results[:stdout]
|
56
|
+
@err = results[:stderr]
|
57
|
+
@process_status = results[:status]
|
58
|
+
|
59
|
+
@error_message = "Timeout (#{@timeout} sec) for this action has been exceeded" if results[:timeout]
|
60
|
+
|
55
61
|
rescue Exception => e
|
56
62
|
@error_message = e.message
|
57
63
|
@backtrace = e.backtrace
|
@@ -128,6 +134,83 @@ module DTK
|
|
128
134
|
|
129
135
|
private
|
130
136
|
|
137
|
+
##
|
138
|
+
# Open3 method extended with timeout, more info https://gist.github.com/pasela/9392115
|
139
|
+
#
|
140
|
+
|
141
|
+
def capture3_with_timeout(*cmd)
|
142
|
+
spawn_opts = Hash === cmd.last ? cmd.pop.dup : {}
|
143
|
+
opts = {
|
144
|
+
:stdin_data => "",
|
145
|
+
:timeout => @timeout,
|
146
|
+
:signal => :TERM,
|
147
|
+
:kill_after => nil,
|
148
|
+
}
|
149
|
+
|
150
|
+
in_r, in_w = IO.pipe
|
151
|
+
out_r, out_w = IO.pipe
|
152
|
+
err_r, err_w = IO.pipe
|
153
|
+
in_w.sync = true
|
154
|
+
|
155
|
+
spawn_opts[:in] = in_r
|
156
|
+
spawn_opts[:out] = out_w
|
157
|
+
spawn_opts[:err] = err_w
|
158
|
+
|
159
|
+
result = {
|
160
|
+
:pid => nil,
|
161
|
+
:status => nil,
|
162
|
+
:stdout => nil,
|
163
|
+
:stderr => nil,
|
164
|
+
:timeout => false,
|
165
|
+
}
|
166
|
+
|
167
|
+
out_reader = nil
|
168
|
+
err_reader = nil
|
169
|
+
wait_thr = nil
|
170
|
+
|
171
|
+
begin
|
172
|
+
Timeout.timeout(opts[:timeout]) do
|
173
|
+
result[:pid] = spawn(*cmd, spawn_opts)
|
174
|
+
wait_thr = Process.detach(result[:pid])
|
175
|
+
in_r.close
|
176
|
+
out_w.close
|
177
|
+
err_w.close
|
178
|
+
|
179
|
+
out_reader = Thread.new { out_r.read }
|
180
|
+
err_reader = Thread.new { err_r.read }
|
181
|
+
|
182
|
+
in_w.close
|
183
|
+
|
184
|
+
result[:status] = wait_thr.value
|
185
|
+
end
|
186
|
+
rescue Timeout::Error
|
187
|
+
result[:timeout] = true
|
188
|
+
pid = result[:pid]
|
189
|
+
Process.kill(opts[:signal], pid)
|
190
|
+
if opts[:kill_after]
|
191
|
+
unless wait_thr.join(opts[:kill_after])
|
192
|
+
Process.kill(:KILL, pid)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
ensure
|
196
|
+
result[:status] = wait_thr.value if wait_thr
|
197
|
+
begin
|
198
|
+
# there is a bug where there is infinite leg on out_reader (e.g. hohup) commands
|
199
|
+
Timeout.timeout(STREAM_TIMEOUT) do
|
200
|
+
result[:stdout] = out_reader.value if out_reader
|
201
|
+
result[:stderr] = err_reader.value if err_reader
|
202
|
+
end
|
203
|
+
rescue Timeout::Error
|
204
|
+
result[:stdout] ||= ''
|
205
|
+
result[:stderr] ||= ''
|
206
|
+
end
|
207
|
+
out_r.close unless out_r.closed?
|
208
|
+
err_r.close unless err_r.closed?
|
209
|
+
end
|
210
|
+
|
211
|
+
result
|
212
|
+
end
|
213
|
+
|
131
214
|
#
|
132
215
|
# Based on stdout-redirect flag
|
133
216
|
#
|
data/lib/position.rb
CHANGED
@@ -96,10 +96,12 @@ module DTK
|
|
96
96
|
def position_git()
|
97
97
|
unless File.directory?(@target_path)
|
98
98
|
begin
|
99
|
+
tries ||= 2
|
99
100
|
g_repo = Git.clone("#{@git_url}", '', :path => @target_path, :branch => @branch)
|
100
101
|
Log.info("Positioner successfully cloned git repository '#{@git_url}@#{@branch}' to location '#{@target_path}'")
|
101
102
|
rescue Exception => e
|
102
103
|
cleanup_path()
|
104
|
+
retry unless (tries -= 1).zero?
|
103
105
|
trigger_error("Positioner unable to clone provided url #{@git_url}. Reasone: #{e.message}", 1, e.backtrace)
|
104
106
|
end
|
105
107
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtk-action-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich PELAVIN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|