ztk 1.5.5 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ztk/command.rb +19 -13
- data/lib/ztk/parallel.rb +10 -2
- data/lib/ztk/version.rb +1 -1
- data/ztk.gemspec +0 -1
- metadata +3 -19
data/lib/ztk/command.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'timeout'
|
3
|
-
require 'childprocess'
|
4
3
|
require 'socket'
|
5
4
|
|
6
5
|
module ZTK
|
@@ -48,8 +47,6 @@ module ZTK
|
|
48
47
|
:silence => false
|
49
48
|
}.merge(configuration))
|
50
49
|
config.ui.logger.debug { "config=#{config.send(:table).inspect}" }
|
51
|
-
|
52
|
-
ChildProcess.posix_spawn = false
|
53
50
|
end
|
54
51
|
|
55
52
|
# Execute Command
|
@@ -98,11 +95,19 @@ module ZTK
|
|
98
95
|
|
99
96
|
start_time = Time.now.utc
|
100
97
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
pid = Process.fork do
|
99
|
+
parent_stdout_reader.close
|
100
|
+
parent_stderr_reader.close
|
101
|
+
|
102
|
+
STDOUT.reopen(child_stdout_writer)
|
103
|
+
STDERR.reopen(child_stderr_writer)
|
104
|
+
STDIN.reopen("/dev/null")
|
105
|
+
|
106
|
+
child_stdout_writer.close
|
107
|
+
child_stderr_writer.close
|
105
108
|
|
109
|
+
Kernel.exec(command)
|
110
|
+
end
|
106
111
|
child_stdout_writer.close
|
107
112
|
child_stderr_writer.close
|
108
113
|
|
@@ -110,14 +115,15 @@ module ZTK
|
|
110
115
|
reader_writer_map = {parent_stdout_reader => options.ui.stdout, parent_stderr_reader => options.ui.stderr}
|
111
116
|
|
112
117
|
direct_log(:info) { log_header("COMMAND") }
|
113
|
-
direct_log(:info) { "#{command}\n" }
|
118
|
+
direct_log(:info) { "#{command.inspect}\n" }
|
114
119
|
direct_log(:info) { log_header("STARTED") }
|
115
120
|
|
116
121
|
begin
|
117
122
|
Timeout.timeout(options.timeout) do
|
118
123
|
loop do
|
119
|
-
reader_writer_map.keys
|
120
|
-
|
124
|
+
pipes = IO.select(reader_writer_map.keys, [], reader_writer_map.keys).first
|
125
|
+
pipes.each do |pipe|
|
126
|
+
data = pipe.read
|
121
127
|
|
122
128
|
if (data.nil? || data.empty?)
|
123
129
|
sleep(0.1)
|
@@ -148,17 +154,17 @@ module ZTK
|
|
148
154
|
|
149
155
|
options.on_progress.nil? or options.on_progress.call
|
150
156
|
end
|
157
|
+
|
151
158
|
break if reader_writer_map.keys.all?{ |reader| reader.eof? }
|
152
159
|
end
|
153
160
|
end
|
154
161
|
rescue Timeout::Error => e
|
155
162
|
direct_log(:fatal) { log_header("TIMEOUT") }
|
156
163
|
log_and_raise(CommandError, "Process timed out after #{options.timeout} seconds!")
|
157
|
-
proc.stop
|
158
164
|
end
|
159
165
|
|
160
|
-
|
161
|
-
exit_code =
|
166
|
+
Process.waitpid(pid)
|
167
|
+
exit_code = $?.exitstatus
|
162
168
|
direct_log(:info) { log_header("STOPPED") }
|
163
169
|
|
164
170
|
parent_stdout_reader.close
|
data/lib/ztk/parallel.rb
CHANGED
@@ -99,9 +99,17 @@ module ZTK
|
|
99
99
|
# Default Maximum Number of Forks
|
100
100
|
MAX_FORKS = case RUBY_PLATFORM
|
101
101
|
when /darwin/ then
|
102
|
-
%x( sysctl hw.ncpu ).
|
102
|
+
%x( sysctl hw.ncpu ).strip.split(':').last.strip.to_i
|
103
103
|
when /linux/ then
|
104
|
-
%x( grep -c processor /proc/cpuinfo ).
|
104
|
+
%x( grep -c processor /proc/cpuinfo ).strip.strip.to_i
|
105
|
+
end
|
106
|
+
|
107
|
+
# Platforms memory capacity in bytes
|
108
|
+
MAX_MEMORY = case RUBY_PLATFORM
|
109
|
+
when /darwin/ then
|
110
|
+
%x( sysctl hw.memsize ).strip.split[1].to_i
|
111
|
+
when /linux/ then
|
112
|
+
(%x( grep MemTotal /proc/meminfo ).strip.split[1].to_i * 1024)
|
105
113
|
end
|
106
114
|
|
107
115
|
# Result Set
|
data/lib/ztk/version.rb
CHANGED
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
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: childprocess
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - '='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 0.3.6
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - '='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 0.3.6
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: erubis
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
281
265
|
version: '0'
|
282
266
|
segments:
|
283
267
|
- 0
|
284
|
-
hash: -
|
268
|
+
hash: -126748681246947343
|
285
269
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
286
270
|
none: false
|
287
271
|
requirements:
|
@@ -290,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
274
|
version: '0'
|
291
275
|
segments:
|
292
276
|
- 0
|
293
|
-
hash: -
|
277
|
+
hash: -126748681246947343
|
294
278
|
requirements: []
|
295
279
|
rubyforge_project:
|
296
280
|
rubygems_version: 1.8.25
|