rbbt-util 5.27.8 → 5.27.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d3d7b4d19322b271a94d3e2fe046158857bbedf9adf79d0408b4c50d2ba9254
4
- data.tar.gz: 78d6fcffe3d5efd08ec42e0493f3f7c731d31001b726ade88802460e5958354b
3
+ metadata.gz: 99b1ad9e8d9403c7f77e22b16497456324c340b08122b765033530f713e35c3c
4
+ data.tar.gz: 2d33590e395b9ca715e1c16d509d0a62a1ebeab2315b700ff4377a08803c89af
5
5
  SHA512:
6
- metadata.gz: cc8ba1db9052fb92dc87bd037b8745f232ff20110b7e3d0da4d2e3c9f0ed90b4bdf18f68887c8a1ad1eb44f1828e9fbd614770259e73deda196047cf4f783d06
7
- data.tar.gz: 3623a36d9282152a71710a71767fb829ce1258f29161451ffc1b0045c0eee152267dd62c8ca8af0e2e3de7f4ef86d9242279c3d34bbd7a3fdfa18841d857ac8a
6
+ metadata.gz: '097ce6c8c16c17441f5a8748ba4ab33afecf6d22d4d54c7ce53475cd642407ae5013346ba482f7fa9375176ab6790febfe030e9f7959ba7b928b5d3762382237'
7
+ data.tar.gz: 2fb616d7d66fc2eb979c9911921faecf163f51dd3323ac127265bcaefd0e8a4e3aab9ef41cc9bdf8bd351d44d4ef2cc388c692d5dc9a2d1b811155f21e3f0889
@@ -261,7 +261,7 @@ module Entity
261
261
 
262
262
  define_method method_name do |*args|
263
263
  id = self.id
264
- persist_name = orig_method_name.to_s << ":" << (Array === id ? Misc.obj2digest(id) : id)
264
+ persist_name = orig_method_name.to_s + ":" << (Array === id ? Misc.obj2digest(id) : id)
265
265
 
266
266
  persist_options = options
267
267
  persist_options = persist_options.merge(:other => {:args => args}) if args and args.any?
@@ -28,7 +28,7 @@ class FixWidthTable
28
28
  else
29
29
  Log.debug "FixWidthTable up-to-date: #{ filename } - (in_memory:#{in_memory})"
30
30
  if in_memory
31
- @file = Open.open(@filename, :mode => 'r:ASCII-ASCII'){|f| StringIO.new f.read}
31
+ @file = Open.open(@filename, :mode => 'r:ASCII-8BIT'){|f| StringIO.new f.read}
32
32
  else
33
33
  @file = File.open(@filename, 'r:ASCII-8BIT')
34
34
  end
@@ -365,12 +365,12 @@ module Persist
365
365
  type ||= :marshal
366
366
 
367
367
  persist_options ||= {}
368
- if type == :memory and persist_options[:file] and persist_options[:persist]
368
+ if type == :memory && persist_options[:file] && persist_options[:persist]
369
369
  repo = persist_options[:repo] || Persist::MEMORY
370
370
  if persist_options[:persist] == :update || persist_options[:update]
371
371
  repo.delete persist_options[:file]
372
372
  end
373
- return repo[persist_options[:file]] ||= yield
373
+ return repo[persist_options[:file]] ||= yield
374
374
  end
375
375
 
376
376
  if FalseClass === persist_options[:persist]
@@ -727,6 +727,8 @@ module TSV
727
727
  Log.exception $!
728
728
  abort_stream(into, $!)
729
729
  raise $!
730
+ ensure
731
+ Log::ProgressBar.remove_bar(bar) if bar
730
732
  end
731
733
 
732
734
  into
@@ -2,6 +2,7 @@ require 'lockfile'
2
2
  require 'digest/md5'
3
3
  require 'cgi'
4
4
  require 'zlib'
5
+ require 'etc'
5
6
  require 'rubygems/package'
6
7
 
7
8
  require 'rbbt/util/tar'
@@ -292,14 +292,21 @@ def self.add_libdir(dir=nil)
292
292
  end
293
293
  end
294
294
 
295
- def self.bootstrap(elems, num = :current, options = {}, &block)
295
+ def self.bootstrap(elems, num = nil, options = {}, &block)
296
296
  IndiferentHash.setup options
297
+
298
+ num = Rbbt::Config.get :cpus, :default_bootstrap_cpus, :bootstrap_cpus if num == :current || num == nil if defined?(Rbbt::Config)
297
299
  num = :current if num.nil?
298
300
  cpus = case num
299
301
  when :current
300
- n = 10
301
- n = elems.length / 2 if n > elems.length/2
302
- n
302
+ n = Etc.nprocessors
303
+ n = elems.length / 2 if n > elems.length/2
304
+
305
+ if $BOOTSTRAPPED_CURRENT && $BOOTSTRAPPED_CURRENT + n > Etc.nprocessors
306
+ 1
307
+ else
308
+ n
309
+ end
303
310
  when String
304
311
  num.to_i
305
312
  when Integer
@@ -318,7 +325,12 @@ def self.add_libdir(dir=nil)
318
325
  respawn = options[:respawn] and options[:cpus] and options[:cpus].to_i > 1
319
326
 
320
327
  index = (0..elems.length-1).to_a.collect{|v| v.to_s }
328
+
321
329
  TSV.traverse index, options do |pos|
330
+ if num == :current
331
+ $BOOTSTRAPPED_CURRENT ||= n
332
+ $BOOTSTRAPPED_CURRENT += 0
333
+ end
322
334
  elem = elems[pos.to_i]
323
335
  elems.annotate elem if elems.respond_to? :annotate
324
336
  res = begin
@@ -401,7 +401,7 @@ module Misc
401
401
 
402
402
  def self.scan_version_text(text, cmd = nil)
403
403
  cmd = "NOCMDGIVE" if cmd.nil? || cmd.empty?
404
- m = text.match(/(?:version.*?|#{cmd}.*?|v)((?:\d+\.)*\d+(?:-[a-z_]+)?)/i)
404
+ m = text.match(/(?:version.*?|#{cmd}.*?|#{cmd.split(/[-_.]/).first}.*?|v)((?:\d+\.)*\d+(?:-[a-z_]+)?)/i)
405
405
  return nil if m.nil?
406
406
  m[1]
407
407
  end
@@ -94,7 +94,8 @@ module Open
94
94
  end
95
95
 
96
96
  begin
97
- wget_options = options.merge( '-O' => '-')
97
+ wget_options = options.dup
98
+ wget_options = wget_options.merge( '-O' => '-') unless options.include?('--output-document')
98
99
  wget_options[:pipe] = pipe unless pipe.nil?
99
100
  wget_options[:stderr] = stderr unless stderr.nil?
100
101
 
@@ -824,4 +825,8 @@ module Open
824
825
  def self.broken_link?(path)
825
826
  File.symlink?(path) && ! File.exists?(File.readlink(path))
826
827
  end
828
+
829
+ def self.download(url, path)
830
+ Open.wget(url, "--output-document" => path)
831
+ end
827
832
  end
@@ -17,14 +17,14 @@ module TmpFile
17
17
 
18
18
  # Creates a random file name, with the given suffix and a random number
19
19
  # up to +max+
20
- def self.random_name(s = "tmp-", max = 10000000)
20
+ def self.random_name(s = "tmp-", max = 1_000_000_000)
21
21
  n = rand(max)
22
22
  s + n.to_s
23
23
  end
24
24
 
25
25
  # Creates a random filename in the temporary directory
26
- def self.tmp_file(s = "tmp-", max=10000000, dir = TMPDIR)
27
- File.expand_path(File.join(dir, random_name(s,max)))
26
+ def self.tmp_file(s = "tmp-", max=1_000_000_000, dir = TMPDIR)
27
+ File.expand_path(File.join(dir, random_name(s, max)))
28
28
  end
29
29
 
30
30
  def self.with_file(content = nil, erase = true, options = {})
@@ -33,7 +33,7 @@ module TmpFile
33
33
 
34
34
  prefix = options[:prefix] || "tmp-"
35
35
  tmpdir = options[:tmpdir] || TMPDIR
36
- max = options[:max] || 10000000
36
+ max = options[:max] || 1_000_000_000
37
37
  tmpfile = tmp_file prefix, max, tmpdir
38
38
  if options[:extension]
39
39
  tmpfile += ".#{options[:extension]}"
@@ -10,9 +10,6 @@ require 'rbbt/workflow/util/provenance'
10
10
 
11
11
  module Workflow
12
12
 
13
- STEP_CACHE = {}
14
- LOAD_STEP_CACHE = {}
15
-
16
13
  class TaskNotFoundException < Exception
17
14
  def initialize(workflow, task = nil)
18
15
  if task
@@ -264,11 +261,11 @@ module Workflow
264
261
  end
265
262
 
266
263
  def step_cache
267
- @step_cache ||= Workflow::STEP_CACHE
264
+ Thread.current[:step_cache] ||= {}
268
265
  end
269
266
 
270
267
  def self.load_step_cache
271
- @load_step_cache ||= Workflow::LOAD_STEP_CACHE
268
+ Thread.current[:load_step_cache] ||= {}
272
269
  end
273
270
 
274
271
 
@@ -418,7 +418,7 @@ module Workflow
418
418
  when :hash
419
419
  clean_inputs = Annotated.purge(inputs)
420
420
  clean_inputs = clean_inputs.collect{|i| Symbol === i ? i.to_s : i }
421
- deps_str = dependencies.collect{|d| Step === d ? d.short_path : d }
421
+ deps_str = dependencies.collect{|d| (Step === d || (defined?(RemoteStep) && RemoteStep === Step)) ? "Step: " << d.short_path : d }
422
422
  key_obj = {:inputs => clean_inputs, :dependencies => deps_str }
423
423
  key_str = Misc.obj2str(key_obj)
424
424
  hash_str = Misc.digest(key_str)
@@ -137,14 +137,16 @@ class RemoteWorkflow
137
137
 
138
138
  post_thread = Thread.new(Thread.current) do |parent|
139
139
  bl = lambda do |rok|
140
- if Net::HTTPOK === rok
140
+ case rok
141
+ when Net::HTTPOK
141
142
  _url = rok["RBBT-STREAMING-JOB-URL"]
142
143
  @url = File.join(task_url, File.basename(_url)) if _url
143
144
  rok.read_body do |c,_a, _b|
144
145
  sin.write c
145
146
  end
146
147
  sin.close
147
- elsif Net::HTTPSeeOther === rok
148
+ when Net::HTTPRedirection, Net::HTTPAccepted
149
+ Thread.current.report_on_exception = false
148
150
  raise TryThis.new(rok)
149
151
  else
150
152
  err = StringIO.new
@@ -178,7 +180,8 @@ class RemoteWorkflow
178
180
  begin
179
181
  RestClient::Request.execute(:method => :post, :url => task_url, :payload => task_params, :block_response => bl)
180
182
  rescue TryThis
181
- RestClient::Request.execute(:method => :get, :url => $!.payload.header[:location], :block_response => bl)
183
+ url = $!.payload["location"]
184
+ RestClient::Request.execute(:method => :get, :url => url, :block_response => bl)
182
185
  end
183
186
  end
184
187
 
@@ -26,8 +26,8 @@ class RemoteStep < Step
26
26
 
27
27
  def cache_file
28
28
  begin
29
- digest = Misc.obj2digest([base_url, task, base_name, inputs])
30
- Rbbt.var.cache.REST[[task, clean_name, digest].compact * "."].find
29
+ digest = Misc.obj2digest([base_url, task.to_s, base_name, inputs])
30
+ Rbbt.var.cache.REST[task.to_s][[clean_name, digest].compact * "."].find
31
31
  rescue
32
32
  Log.exception $!
33
33
  raise $!
@@ -143,7 +143,11 @@ class RemoteStep < Step
143
143
  @info = Persist.memory("RemoteSteps Info", :url => @url, :persist => true, :update => update) do
144
144
  @last_info_time = Time.now
145
145
  init_job unless @url
146
- info = @adaptor.get_json(File.join(@url, 'info'))
146
+ info = begin
147
+ @adaptor.get_json(File.join(@url, 'info'))
148
+ rescue
149
+ {:status => :noinfo}
150
+ end
147
151
  info = RemoteWorkflow.fix_hash(info)
148
152
  info[:status] = info[:status].to_sym if String === info[:status]
149
153
  info
@@ -243,6 +247,7 @@ class RemoteStep < Step
243
247
  def join
244
248
  return true if cache_files.any?
245
249
  init_job unless @url
250
+ produce unless @started
246
251
  Log.debug{ "Joining RemoteStep: #{path}" }
247
252
 
248
253
  if IO === @result
@@ -258,7 +263,6 @@ class RemoteStep < Step
258
263
  sleep 1 unless self.done? || self.aborted? || self.error?
259
264
  while not (self.done? || self.aborted? || self.error?)
260
265
  sleep 3
261
- iif [self.done?, self.status, self.info]
262
266
  end
263
267
  end
264
268
 
@@ -311,6 +315,10 @@ class RemoteStep < Step
311
315
  end
312
316
  end
313
317
 
318
+ def short_path
319
+ init_job unless @url
320
+ [@task, @name] * "/"
321
+ end
314
322
 
315
323
  def input_checks
316
324
  []
@@ -15,6 +15,7 @@ $ rbbt app start [options]
15
15
  -Ho--Host* Host name
16
16
  -B--Bind* Bind IP
17
17
  -p--port* TCP port
18
+ -w--workers* Number of workers for cluster mode (puma)
18
19
  -s--server* Server type: thin, webrick, unicorn, etc
19
20
  -f--finder Start server with finder functionality
20
21
  -fs--file_server Activate file serving for resources
@@ -84,6 +85,12 @@ Misc.in_dir(app_dir) do
84
85
  end
85
86
  end
86
87
 
88
+ fixed_options = {}
89
+ options.each do |k,v| fixed_options[k.to_sym] = v end
90
+ options = fixed_options
91
+
92
+ options[:workers] = options[:workers].to_i if options[:workers]
93
+
87
94
  case server
88
95
  when 'passenger'
89
96
  system ENV, "env RBBT_LOG=0 passenger start -R '#{config_ru_file}' -p #{options[:Port] || "2887"}"
@@ -91,6 +98,7 @@ Misc.in_dir(app_dir) do
91
98
  system ENV, "puma '#{config_ru_file}' -p #{options[:Port] || "2887"} -w 3 -t 8:32 --preload"
92
99
  else
93
100
  options[:config] = config_ru_file
101
+ options[:threads] = "8:8"
94
102
  Rack::Server.start(options)
95
103
  end
96
104
  end
@@ -97,7 +97,7 @@ TSV.traverse jobs do |file,i|
97
97
  else
98
98
  info = begin
99
99
  Open.open(i[:info_file]) do |f|
100
- Step::INFO_SERIALIAZER.load(f)
100
+ Step::INFO_SERIALIZER.load(f)
101
101
  end
102
102
  rescue
103
103
  {:status => :noinfo}
@@ -134,7 +134,7 @@ TSV.traverse jobs do |file,i|
134
134
  end
135
135
  end
136
136
 
137
- if (force and status !~ /done/) or
137
+ if (force && status !~ /done/) or
138
138
  status =~ /\b(old|dirty|nopid|error|missing|aborted|dead|sync)$/ or
139
139
  (status == "noinfo" and not done) or
140
140
  status == ""
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+
6
+ options = SOPT.setup <<EOF
7
+ Read a TSV file and dump it
8
+
9
+ $ rbbt tsv read [options] <filename.tsv|->
10
+
11
+ Use - to read from STDIN
12
+
13
+ -k--key_field* Key field
14
+ -f--fields* Fields
15
+ -t--type* Type
16
+ -m--merge* Merge from multiple rows
17
+ -h--help Print this help
18
+
19
+ EOF
20
+ rbbt_usage and exit 0 if options[:help]
21
+
22
+ file = ARGV.shift
23
+
24
+ file = STDIN if file == '-'
25
+
26
+ tsv = TSV.open file, :merge => true, :type => :double
27
+
28
+ puts tsv.to_unmerged_expanded_s
@@ -153,7 +153,7 @@ if recursive
153
153
  dep = deps.shift
154
154
  inputs = {} if inputs.nil?
155
155
  inputs = inputs.merge(dep.info[:inputs] || {})
156
- deps = deps.concat dep.dependencies
156
+ deps = deps.concat dep.dependencies if dep.dependencies
157
157
  end
158
158
 
159
159
  inputs = inputs.merge step.archived_inputs
@@ -123,15 +123,11 @@ TmpFile.with_file do |app_dir|
123
123
  else
124
124
  options[:config] = config_ru_file
125
125
 
126
- clean_options = {}
127
- options.each do |k,v|
128
- begin
129
- clean_options[k.to_sym] = v
130
- rescue
131
- end
132
- end
126
+ fixed_options = {}
127
+ options.each do |k,v| fixed_options[k.to_sym] = v end
128
+ options = fixed_options
133
129
 
134
- Rack::Server.start(clean_options)
130
+ Rack::Server.start(options)
135
131
  end
136
132
  end
137
133
  end
@@ -337,6 +337,8 @@ if clean_task
337
337
  dep.clean
338
338
  dep.set_info :status, :cleaned
339
339
  end
340
+
341
+ job.clean if job.task_name.to_s == clean_task.to_s
340
342
  end
341
343
  end
342
344
 
@@ -690,5 +690,30 @@ Written by Mike Haertel and others, see
690
690
  EOF
691
691
  assert_equal "3.1", Misc.scan_version_text(txt, "grep")
692
692
  end
693
+
694
+ def test_bootstrap_current_only_once
695
+
696
+
697
+ max = Etc.nprocessors * 10
698
+ TmpFile.with_file do |f|
699
+ RbbtSemaphore.with_semaphore(1) do |sem|
700
+ Misc.bootstrap (1..max).to_a do
701
+ Open.open(f, :mode => 'a') do |sin|
702
+ sin.puts Process.pid.to_s
703
+ end
704
+ Misc.bootstrap (1..10).to_a do
705
+ RbbtSemaphore.synchronize(sem) do
706
+ Open.open(f, :mode => 'a') do |sin|
707
+ sin.puts [Process.ppid.to_s, Process.pid.to_s] * ":"
708
+ end
709
+ end
710
+ end
711
+ end
712
+ end
713
+ assert_equal max * 10 + max, Open.read(f).split("\n").length
714
+ assert_equal Etc.nprocessors * 2, Open.read(f).split("\n").uniq.length
715
+ end
716
+
717
+ end
693
718
  end
694
719
 
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.27.8
4
+ version: 5.27.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -403,6 +403,7 @@ files:
403
403
  - share/rbbt_commands/tsv/sort
404
404
  - share/rbbt_commands/tsv/subset
405
405
  - share/rbbt_commands/tsv/transpose
406
+ - share/rbbt_commands/tsv/uncollapse
406
407
  - share/rbbt_commands/tsv/unzip
407
408
  - share/rbbt_commands/tsv/values
408
409
  - share/rbbt_commands/tsv/write_excel