rbbt-util 5.21.129 → 5.21.130
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/association/index.rb +5 -2
- data/lib/rbbt/resource.rb +4 -2
- data/lib/rbbt/tsv.rb +2 -0
- data/lib/rbbt/tsv/accessor.rb +2 -2
- data/lib/rbbt/tsv/parser.rb +1 -0
- data/lib/rbbt/tsv/serializers.rb +0 -1
- data/lib/rbbt/util/cmd.rb +34 -14
- data/lib/rbbt/util/concurrency/processes.rb +6 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +3 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +7 -3
- data/lib/rbbt/util/misc/development.rb +6 -6
- data/lib/rbbt/util/misc/exceptions.rb +2 -0
- data/lib/rbbt/util/misc/objects.rb +22 -2
- data/lib/rbbt/util/misc/pipes.rb +14 -0
- data/lib/rbbt/util/misc/system.rb +1 -1
- data/lib/rbbt/util/open.rb +8 -9
- data/lib/rbbt/workflow/accessor.rb +1 -1
- data/share/install/software/lib/install_helpers +4 -0
- data/share/rbbt_commands/workflow/cmd +1 -3
- data/share/rbbt_commands/workflow/server +6 -0
- data/test/rbbt/util/test_misc.rb +12 -1
- 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: 6996eb266a74a60fe3d8dbe789eccdc1aef28f63
|
4
|
+
data.tar.gz: cae5ae771a6fb59164c08952b189d399343e2be7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60e9b3df6233872a4cbabd811a136d0778e7ba7a57833539c802ca7a7a7d8b94d3593fa35f5523d38d008e1327b579ad39cb96b11fcb94682fc569e529d56c51
|
7
|
+
data.tar.gz: b4aaa61f8fe810af9f0a6bdcf45b95bd6903563ffe21421f7987a7701f03af6c3fcb2dcb8be5c62ebc6ea842502229f9577bb2c2f5dbf87f01818fbb71854b21
|
@@ -6,6 +6,7 @@ module Association
|
|
6
6
|
def self.index(file, options = nil, persist_options = nil)
|
7
7
|
options = options.nil? ? {} : options.dup
|
8
8
|
persist_options = persist_options.nil? ? Misc.pull_keys(options, :persist) : persist_options.dup
|
9
|
+
persist_options[:serializer] ||= options[:serializer] if options.include?(:serializer)
|
9
10
|
|
10
11
|
persist_options = Misc.add_defaults persist_options.dup, :persist => true, :dir => Rbbt.var.associations
|
11
12
|
persist = persist_options[:persist]
|
@@ -16,6 +17,8 @@ module Association
|
|
16
17
|
recycle = options[:recycle]
|
17
18
|
undirected = options[:undirected]
|
18
19
|
|
20
|
+
serializer = persist_options[:serializer] || :list
|
21
|
+
|
19
22
|
persist_options[:file] = persist_options[:file] + '.database' if persist_options[:file]
|
20
23
|
|
21
24
|
database = open(file, options, persist_options.dup.merge(:engine => "HDB"))
|
@@ -29,12 +32,12 @@ module Association
|
|
29
32
|
|
30
33
|
key_field = [source_field, target_field, undirected ? "undirected" : nil].compact * "~"
|
31
34
|
|
32
|
-
TSV.setup(data, :key_field => key_field, :fields => fields[1..-1], :type => :list, :serializer =>
|
35
|
+
TSV.setup(data, :key_field => key_field, :fields => fields[1..-1], :type => :list, :serializer => serializer, :namespace => database.namespace)
|
33
36
|
|
34
37
|
data.key_field = key_field
|
35
38
|
data.fields = fields[1..-1]
|
36
39
|
data.type = :list
|
37
|
-
data.serializer
|
40
|
+
data.serializer ||= serializer
|
38
41
|
|
39
42
|
database.with_unnamed do
|
40
43
|
database.with_monitor(options[:monitor]) do
|
data/lib/rbbt/resource.rb
CHANGED
@@ -153,7 +153,9 @@ module Resource
|
|
153
153
|
when :string
|
154
154
|
Misc.sensiblewrite(final_path, content)
|
155
155
|
when :url
|
156
|
-
|
156
|
+
options = {}
|
157
|
+
options[:noz] = true if Open.gzip?(final_path) || Open.bgzip?(final_path) || Open.zip?(final_path)
|
158
|
+
Misc.sensiblewrite(final_path, Open.open(content, options))
|
157
159
|
when :proc
|
158
160
|
data = case content.arity
|
159
161
|
when 0
|
@@ -192,7 +194,7 @@ source "$INSTALL_HELPER_FILE"
|
|
192
194
|
EOF
|
193
195
|
|
194
196
|
script = preamble + "\n" + Open.read(content)
|
195
|
-
install_io = CMD.cmd('bash', :in => script, :log => true, :pipe => true)
|
197
|
+
install_io = CMD.cmd('bash', :in => script, :log => true, :pipe => true, :stderr => true)
|
196
198
|
while line = install_io.gets
|
197
199
|
Log.debug line
|
198
200
|
end
|
data/lib/rbbt/tsv.rb
CHANGED
@@ -128,10 +128,12 @@ module TSV
|
|
128
128
|
case
|
129
129
|
when Path === stream
|
130
130
|
stream.open do |f|
|
131
|
+
f.no_fail = false if ConcurrentStream === f
|
131
132
|
Parser.new f, options
|
132
133
|
end
|
133
134
|
when (String === stream and stream.length < 300 and (Open.exists? stream or Open.remote? stream))
|
134
135
|
Open.open(stream) do |f|
|
136
|
+
f.no_fail = false if ConcurrentStream === f
|
135
137
|
Parser.new f, options
|
136
138
|
end
|
137
139
|
else
|
data/lib/rbbt/tsv/accessor.rb
CHANGED
@@ -193,14 +193,14 @@ module TSV
|
|
193
193
|
def serializer=(serializer)
|
194
194
|
@serializer = serializer
|
195
195
|
self.send(:[]=, KEY_PREFIX + 'serializer', dump_entry_value(serializer), :entry_key)
|
196
|
-
@serializar_module = serializer.nil? ? TSV::CleanSerializer : SERIALIZER_ALIAS[serializer.to_sym]
|
196
|
+
@serializar_module = serializer.nil? ? TSV::CleanSerializer : (Module === serializer ? serializer : SERIALIZER_ALIAS[serializer.to_sym])
|
197
197
|
end
|
198
198
|
|
199
199
|
|
200
200
|
def serializer_module
|
201
201
|
@serializer_module ||= begin
|
202
202
|
serializer = self.serializer
|
203
|
-
mod = serializer.nil? ? TSV::CleanSerializer : SERIALIZER_ALIAS[serializer.to_sym]
|
203
|
+
mod = serializer.nil? ? TSV::CleanSerializer : (Module === serializer ? serializer : SERIALIZER_ALIAS[serializer.to_sym])
|
204
204
|
raise "No serializer_module for: #{ serializer.inspect }" if mod.nil?
|
205
205
|
mod
|
206
206
|
end
|
data/lib/rbbt/tsv/parser.rb
CHANGED
data/lib/rbbt/tsv/serializers.rb
CHANGED
data/lib/rbbt/util/cmd.rb
CHANGED
@@ -134,7 +134,7 @@ module CMD
|
|
134
134
|
if pipe
|
135
135
|
err_thread = Thread.new do
|
136
136
|
while line = serr.gets
|
137
|
-
Log.log line, stderr if Integer === stderr and log
|
137
|
+
Log.log "STDERR [#{pid}]: " + line, stderr if Integer === stderr and log
|
138
138
|
end
|
139
139
|
serr.close
|
140
140
|
end
|
@@ -144,27 +144,47 @@ module CMD
|
|
144
144
|
sout
|
145
145
|
else
|
146
146
|
err = ""
|
147
|
-
Thread.new do
|
147
|
+
err_thread = Thread.new do
|
148
148
|
while not serr.eof?
|
149
149
|
err << serr.gets if Integer === stderr
|
150
150
|
end
|
151
|
-
|
152
|
-
|
151
|
+
serr.close
|
152
|
+
end
|
153
153
|
|
154
|
-
|
154
|
+
ConcurrentStream.setup sout, :pids => pids, :threads => [in_thread, err_thread].compact, :autojoin => no_wait, :no_fail => no_fail
|
155
155
|
|
156
|
-
|
157
|
-
|
156
|
+
out = StringIO.new sout.read
|
157
|
+
sout.close unless sout.closed?
|
158
158
|
|
159
|
-
|
159
|
+
Process.waitpid pid
|
160
160
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
161
|
+
if not $?.success? and not no_fail
|
162
|
+
raise ProcessFailed.new "Command [#{pid}] #{cmd} failed with error status #{$?.exitstatus}.\n#{err}"
|
163
|
+
else
|
164
|
+
Log.log err, stderr if Integer === stderr and log
|
165
|
+
end
|
166
|
+
|
167
|
+
out
|
168
|
+
end
|
169
|
+
end
|
166
170
|
|
167
|
-
|
171
|
+
def self.cmd_log(*args)
|
172
|
+
all_args = *args
|
173
|
+
|
174
|
+
all_args << {} unless Hash === all_args.last
|
175
|
+
all_args.last[:log] = true
|
176
|
+
all_args.last[:pipe] = true
|
177
|
+
|
178
|
+
io = cmd(*all_args)
|
179
|
+
pid = io.pids.first
|
180
|
+
while line = io.gets
|
181
|
+
if pid
|
182
|
+
Log.debug "STDOUT [#{pid}]: " + line
|
183
|
+
else
|
184
|
+
Log.debug "STDOUT: " + line
|
185
|
+
end
|
168
186
|
end
|
187
|
+
io.join
|
188
|
+
nil
|
169
189
|
end
|
170
190
|
end
|
@@ -82,6 +82,12 @@ class RbbtProcessQueue
|
|
82
82
|
rescue Exception
|
83
83
|
Log.warn "Process monitor exception: #{$!.message}"
|
84
84
|
@processes.each{|p| p.abort }
|
85
|
+
@processes.each{|p|
|
86
|
+
begin
|
87
|
+
p.join
|
88
|
+
rescue ProcessFailed
|
89
|
+
end
|
90
|
+
}
|
85
91
|
@callback_thread.raise $! if @callback_thread and @callback_thread.alive?
|
86
92
|
raise $!
|
87
93
|
end
|
@@ -114,7 +114,9 @@ class RbbtProcessQueue
|
|
114
114
|
Log.high "Worker #{Process.pid} respawning to #{@current}"
|
115
115
|
end
|
116
116
|
rescue Aborted, Interrupt
|
117
|
-
Log.warn "Worker #{Process.pid} aborted"
|
117
|
+
Log.warn "Worker #{Process.pid} aborted. Current #{@current} #{Misc.pid_exists?(@current) ? "exists" : "does not exist"}"
|
118
|
+
Process.kill "INT", @current if Misc.pid_exists? @current
|
119
|
+
@callback_queue.close_write if @callback_queue
|
118
120
|
Kernel.exit! 0
|
119
121
|
rescue Exception
|
120
122
|
Log.exception $!
|
@@ -81,8 +81,12 @@ module ConcurrentStream
|
|
81
81
|
begin
|
82
82
|
t.join #unless FalseClass === t.status
|
83
83
|
rescue Exception
|
84
|
-
|
85
|
-
|
84
|
+
if no_fail
|
85
|
+
Log.low "Not failing on exception joining thread in ConcurrenStream: #{filename}"
|
86
|
+
else
|
87
|
+
Log.warn "Exception joining thread in ConcurrenStream: #{filename}"
|
88
|
+
raise $!
|
89
|
+
end
|
86
90
|
end
|
87
91
|
end
|
88
92
|
end
|
@@ -190,7 +194,7 @@ module ConcurrentStream
|
|
190
194
|
end
|
191
195
|
end
|
192
196
|
|
193
|
-
def
|
197
|
+
def close(*args)
|
194
198
|
if autojoin
|
195
199
|
begin
|
196
200
|
super(*args)
|
@@ -320,12 +320,12 @@ def self.add_libdir(dir=nil)
|
|
320
320
|
TSV.traverse index, options do |pos|
|
321
321
|
elem = elems[pos.to_i]
|
322
322
|
elems.annotate elem if elems.respond_to? :annotate
|
323
|
-
begin
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
323
|
+
res = begin
|
324
|
+
yield elem
|
325
|
+
rescue Interrupt
|
326
|
+
Log.warn "Process #{Process.pid} was aborted"
|
327
|
+
raise $!
|
328
|
+
end
|
329
329
|
res = nil unless options[:into]
|
330
330
|
raise RbbtProcessQueue::RbbtProcessQueueWorker::Respawn, res if respawn == :always and cpus > 1
|
331
331
|
res
|
@@ -63,16 +63,36 @@ module Misc
|
|
63
63
|
current
|
64
64
|
end
|
65
65
|
|
66
|
-
def self.
|
66
|
+
def self._zip_fields(array, max = nil)
|
67
67
|
return [] if array.nil? or array.empty? or (first = array.first).nil?
|
68
|
-
max = array.collect{|l| l.length}.max
|
68
|
+
max = array.collect{|l| l.length}.max if max.nil?
|
69
69
|
rest = array[1..-1].collect{|v|
|
70
70
|
v.length == 1 & max > 1 ? v * max : v
|
71
71
|
}
|
72
72
|
first = first * max if first.length == 1 and max > 1
|
73
|
+
|
73
74
|
first.zip(*rest)
|
74
75
|
end
|
75
76
|
|
77
|
+
def self.zip_fields(array)
|
78
|
+
if array.length < 10000
|
79
|
+
_zip_fields(array)
|
80
|
+
else
|
81
|
+
zipped_slices = []
|
82
|
+
max = array.collect{|l| l.length}.max
|
83
|
+
array.each_slice(10000) do |slice|
|
84
|
+
zipped_slices << _zip_fields(slice, max)
|
85
|
+
end
|
86
|
+
new = zipped_slices.first
|
87
|
+
zipped_slices[1..-1].each do |rest|
|
88
|
+
rest.each_with_index do |list,i|
|
89
|
+
new[i].concat list
|
90
|
+
end
|
91
|
+
end
|
92
|
+
new
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
76
96
|
def self.choose(array, select)
|
77
97
|
array.zip(select).select{|e,s| s }.collect{|e,s| e }
|
78
98
|
end
|
data/lib/rbbt/util/misc/pipes.rb
CHANGED
@@ -32,6 +32,17 @@ module Misc
|
|
32
32
|
Log.debug{"Creating pipe #{[res.last.inspect,res.first.inspect] * " => "}"}
|
33
33
|
res
|
34
34
|
end
|
35
|
+
|
36
|
+
def self.with_fifo(path = nil, &block)
|
37
|
+
begin
|
38
|
+
erase = path.nil?
|
39
|
+
path = TmpFile.tmp_file if path.nil?
|
40
|
+
File.mkfifo path
|
41
|
+
yield path
|
42
|
+
ensure
|
43
|
+
FileUtils.rm path if erase
|
44
|
+
end
|
45
|
+
end
|
35
46
|
|
36
47
|
def self.release_pipes(*pipes)
|
37
48
|
PIPE_MUTEX.synchronize do
|
@@ -73,6 +84,7 @@ module Misc
|
|
73
84
|
end
|
74
85
|
Kernel.exit! 0
|
75
86
|
}
|
87
|
+
sin.close
|
76
88
|
|
77
89
|
ConcurrentStream.setup sout, :pids => [pid]
|
78
90
|
else
|
@@ -207,6 +219,8 @@ module Misc
|
|
207
219
|
ConcurrentStream.setup sout, :threads => splitter_thread, :filename => filename, :_pair => stream
|
208
220
|
end
|
209
221
|
|
222
|
+
out_pipes.first.autojoin = true
|
223
|
+
|
210
224
|
out_pipes.first.callback = Proc.new do
|
211
225
|
stream.join
|
212
226
|
in_pipes[1..-1].each do |sin|
|
data/lib/rbbt/util/open.rb
CHANGED
@@ -393,27 +393,26 @@ module Open
|
|
393
393
|
io = gunzip(io) if ((String === url and gzip?(url)) and not options[:noz]) or options[:gzip]
|
394
394
|
io = bgunzip(io) if ((String === url and bgzip?(url)) and not options[:noz]) or options[:bgzip]
|
395
395
|
|
396
|
+
class << io;
|
397
|
+
attr_accessor :filename
|
398
|
+
end
|
399
|
+
|
400
|
+
io.filename = url.to_s
|
401
|
+
|
396
402
|
if block_given?
|
397
403
|
begin
|
398
404
|
return yield(io)
|
405
|
+
rescue DontClose
|
399
406
|
rescue Exception
|
400
407
|
io.abort if io.respond_to? :abort
|
401
408
|
io.join if io.respond_to? :join
|
402
409
|
raise $!
|
403
410
|
ensure
|
404
|
-
io.join if io.respond_to? :join
|
405
411
|
io.close if io.respond_to? :close and not io.closed?
|
412
|
+
io.join if io.respond_to? :join
|
406
413
|
end
|
407
|
-
else
|
408
|
-
io
|
409
414
|
end
|
410
415
|
|
411
|
-
class << io;
|
412
|
-
attr_accessor :filename
|
413
|
-
end
|
414
|
-
|
415
|
-
io.filename = url.to_s
|
416
|
-
|
417
416
|
io
|
418
417
|
end
|
419
418
|
|
@@ -770,7 +770,7 @@ module Workflow
|
|
770
770
|
rec_dependency = all_d.flatten.select{|d| d.task_name.to_sym == v }.first
|
771
771
|
|
772
772
|
if rec_dependency.nil?
|
773
|
-
if
|
773
|
+
if _inputs.include? v
|
774
774
|
_inputs[i] = _inputs.delete(v)
|
775
775
|
else
|
776
776
|
_inputs[i] = v unless _inputs.include? i
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
|
2
3
|
require 'rbbt-util'
|
3
4
|
require 'rbbt/util/simpleopt'
|
@@ -22,6 +23,7 @@ $ rbbt workflow server [options] <Workflow>
|
|
22
23
|
-R--requires* Require a list of files
|
23
24
|
--views* Directory with view templates
|
24
25
|
--stream Activate streaming of workflow tasks
|
26
|
+
--export_all Export all workflow tasks (use with caution!)
|
25
27
|
--export* Export workflow tasks (asynchronous)
|
26
28
|
--export_asynchronous* Export workflow tasks as asynchronous
|
27
29
|
--export_synchronous* Export workflow tasks as synchronous
|
@@ -83,6 +85,10 @@ TmpFile.with_file do |app_dir|
|
|
83
85
|
ENV["RACK_ENV"] = options[:environment] if options.include?(:environment)
|
84
86
|
ENV["RBBT_VIEWS_DIR"] = options[:views] if options.include?(:views)
|
85
87
|
|
88
|
+
if options[:export_all]
|
89
|
+
ENV["RBBT_WORKFLOW_EXPORT_ALL"] = 'true'
|
90
|
+
end
|
91
|
+
|
86
92
|
if options[:stream]
|
87
93
|
raise "No streaming available for any server other than puma" unless true or options[:server].include? 'puma'
|
88
94
|
ENV["RBBT_WORKFLOW_TASK_STREAM"] = 'true'
|
data/test/rbbt/util/test_misc.rb
CHANGED
@@ -171,6 +171,7 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
171
171
|
sleep 0.5
|
172
172
|
sin.puts "LINE #{ i }"
|
173
173
|
end
|
174
|
+
sin.close
|
174
175
|
end
|
175
176
|
|
176
177
|
time = Time.now
|
@@ -240,12 +241,14 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
240
241
|
sin.puts line.strip.reverse
|
241
242
|
end
|
242
243
|
end
|
244
|
+
stream2.close
|
243
245
|
|
244
246
|
stream5 = Misc.open_pipe(true) do |sin|
|
245
247
|
while line = stream3.gets
|
246
248
|
sin.puts line.strip.downcase
|
247
249
|
end
|
248
250
|
end
|
251
|
+
stream3.close
|
249
252
|
|
250
253
|
lines1 = []
|
251
254
|
th1 = Thread.new do
|
@@ -369,6 +372,13 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
369
372
|
assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
|
370
373
|
end
|
371
374
|
|
375
|
+
def test_zip_fields_large
|
376
|
+
current = (1..1500).to_a.collect{|i| ["A#{i}", "B#{i}"]}
|
377
|
+
assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
|
378
|
+
current = (1..150000).to_a.collect{|i| ["A#{i}", "B#{i}"]}
|
379
|
+
assert_equal current, Misc.zip_fields(Misc.zip_fields(current))
|
380
|
+
end
|
381
|
+
|
372
382
|
def test_zip_fields_comp
|
373
383
|
current = [[:a,1], [:b,2], [:c]]
|
374
384
|
assert_equal [[:a, :b, :c],[1,2,nil]], Misc.zip_fields(current)
|
@@ -423,7 +433,8 @@ eum fugiat quo voluptas nulla pariatur?"
|
|
423
433
|
end
|
424
434
|
|
425
435
|
def test_tarize
|
426
|
-
|
436
|
+
dir = Path.caller_lib_dir(__FILE__)
|
437
|
+
path = File.expand_path(dir)
|
427
438
|
stream = Misc.tarize(path)
|
428
439
|
TmpFile.with_file do |res|
|
429
440
|
Misc.in_dir(res) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.21.
|
4
|
+
version: 5.21.130
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|