miga-base 0.7.20.0 → 0.7.20.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de9486ffe4bff4fd61295c004f36af331ce5a50645f4aa706076a38d3523ee38
4
- data.tar.gz: 60ded180b92cfb27729a4844c00713b4e78bf08b6a1f8ebf30f6bdccd24eb769
3
+ metadata.gz: 76b06be04db6bb162666752f374da5a3adab38e010acf8a07f20fc2e8f97e75b
4
+ data.tar.gz: 6c4f9b9118b21b11921b4c0a70ae99f3b1728d5737175ca5b9f23088ff985063
5
5
  SHA512:
6
- metadata.gz: 7a5e89cf299d72c2b3fb9a267923caef0ecfc399cabfec71011e9ebc3c37d874cb8a93e16d169db7c3bbda1f54d3ab5863ba889341295339b69673d3457edef7
7
- data.tar.gz: 4ac7cf2785e42afd17f19749632e1deda80cecfa10103f64d4bc366a29e4a8acf9ead5e8a412ae1b11ba966c6dc9501017cb7dbee2572ebcbc835e9db0341a7b
6
+ metadata.gz: d90839141adeb99d0551d0228c7b5806b11a971852bf2ca8040f419af79330be47fc7abe7f1bffec35fe935b3857a1631c860d8e6aa877ba74eb1524d24f8153
7
+ data.tar.gz: baeee018956a1877065e2e9b5f689e1dc99af71cecc2705f951ab384b05b5760cffd7d85218068bb674541cb766a585add60c5b23a6209c15e2276b369d0f1b0
@@ -103,7 +103,7 @@ class MiGA::Daemon < MiGA::MiGA
103
103
  ##
104
104
  # Queue maintenance tasks as an analysis job
105
105
  def queue_maintenance
106
- return if bypass_maintenance?
106
+ return if bypass_maintenance? || shutdown_when_done?
107
107
 
108
108
  say 'Queueing maintenance tasks'
109
109
  queue_job(:maintenance)
@@ -214,29 +214,38 @@ class MiGA::Daemon < MiGA::MiGA
214
214
  return nil unless get_job(job, ds).nil?
215
215
 
216
216
  ds_name = (ds.nil? ? 'miga-project' : ds.name)
217
- say 'Queueing %s:%s' % [ds_name, job]
217
+ task_name = "#{project.metadata[:name][0..9]}:#{job}:#{ds_name}"
218
+ to_run = { ds: ds, ds_name: ds_name, job: job, task_name: task_name }
219
+ say 'Queueing %s:%s' % [to_run[:ds_name], to_run[:job]]
220
+ @jobs_to_run << to_run
221
+ end
222
+
223
+ ##
224
+ # Construct the command for the given job definition with current
225
+ # daemon settings
226
+ def job_cmd(to_run)
218
227
  vars = {
219
228
  'PROJECT' => project.path,
220
229
  'RUNTYPE' => runopts(:type),
221
230
  'CORES' => ppn,
222
231
  'MIGA' => MiGA::MiGA.root_path
223
232
  }
224
- vars['DATASET'] = ds.name unless ds.nil?
225
- log_dir = File.expand_path("daemon/#{job}", project.path)
226
- Dir.mkdir(log_dir) unless Dir.exist? log_dir
227
- task_name = "#{project.metadata[:name][0..9]}:#{job}:#{ds_name}"
228
- to_run = { ds: ds, ds_name: ds_name, job: job, task_name: task_name }
229
- to_run[:cmd] = runopts(:cmd).miga_variables(
230
- script: MiGA::MiGA.script_path(job, miga: vars['MIGA'], project: project),
233
+ vars['DATASET'] = to_run[:ds].name unless to_run[:ds].nil?
234
+ log_dir = File.expand_path("daemon/#{to_run[:job]}", project.path)
235
+ FileUtils.mkdir_p(log_dir)
236
+ var_hsh = {
237
+ script: MiGA::MiGA.script_path(
238
+ to_run[:job], miga: vars['MIGA'], project: project
239
+ ),
231
240
  vars: vars.map do |k, v|
232
241
  runopts(:var).miga_variables(key: k, value: v)
233
242
  end.join(runopts(:varsep)),
234
243
  cpus: ppn,
235
- log: File.expand_path("#{ds_name}.log", log_dir),
236
- task_name: task_name,
237
- miga: File.expand_path('bin/miga', MiGA::MiGA.root_path).shellescape
238
- )
239
- @jobs_to_run << to_run
244
+ log: File.join(log_dir, "#{to_run[:ds_name]}.log"),
245
+ task_name: to_run[:task_name],
246
+ miga: File.join(MiGA::MiGA.root_path, 'bin/miga').shellescape
247
+ }
248
+ runopts(:cmd).miga_variables(var_hsh)
240
249
  end
241
250
 
242
251
  ##
@@ -312,6 +321,7 @@ class MiGA::Daemon < MiGA::MiGA
312
321
  # Launch the job described by Hash +job+ to +hostk+-th host
313
322
  def launch_job(job, hostk = nil)
314
323
  # Execute job
324
+ job[:cmd] = job_cmd(job)
315
325
  case runopts(:type)
316
326
  when 'ssh'
317
327
  # Remote job
@@ -93,7 +93,7 @@ module MiGA::Daemon::Base
93
93
  ##
94
94
  # Display log instead of the progress summary
95
95
  def show_log!
96
- @show_log = true
96
+ @runopts[:show_log] = true
97
97
  end
98
98
 
99
99
  ##
@@ -48,10 +48,11 @@ module MiGA::Project::Dataset
48
48
  # Add dataset identified by +name+ and return MiGA::Dataset.
49
49
  def add_dataset(name)
50
50
  unless metadata[:datasets].include? name
51
- MiGA::Dataset.new(self, name)
51
+ ds = MiGA::Dataset.new(self, name)
52
52
  @metadata[:datasets] << name
53
53
  @dataset_names_hash = nil # Ensure loading even if +do_not_save+ is true
54
54
  save
55
+ # TODO redo_project_steps if ds.ref?
55
56
  pull_hook(:on_add_dataset, name)
56
57
  end
57
58
  dataset(name)
@@ -17,7 +17,7 @@ class MiGA::TaxIndex < MiGA::MiGA
17
17
  ##
18
18
  # Initialize an empty MiGA::TaxIndex
19
19
  def initialize
20
- @root = MiGA::TaxIndexTaxon.new :root, 'biota'
20
+ @root = MiGA::TaxIndexTaxon.new(:root, 'biota')
21
21
  @datasets = []
22
22
  end
23
23
 
@@ -37,21 +37,22 @@ class MiGA::TaxIndex < MiGA::MiGA
37
37
  end
38
38
 
39
39
  ##
40
- # Finds all the taxa in the collection at the +rank+ taxonomic rank.
40
+ # Finds all the taxa in the collection at the +rank+ taxonomic rank
41
41
  def taxa_by_rank(rank)
42
42
  rank = MiGA::Taxonomy.normalize_rank(rank)
43
43
  taxa = [@root]
44
44
  select = []
45
45
  loop do
46
46
  new_taxa = []
47
- taxa.map { |tx| tx.children }.flatten.each do |ch|
47
+ taxa.map(&:children).flatten.each do |ch|
48
48
  if ch.rank == rank
49
49
  select << ch
50
- elsif not ch.children.empty?
50
+ elsif !ch.children.empty?
51
51
  new_taxa << ch
52
52
  end
53
53
  end
54
- break if new_taxa.empty?
54
+ taxa = new_taxa
55
+ break if taxa.empty?
55
56
  end
56
57
  select
57
58
  end
@@ -60,7 +61,8 @@ class MiGA::TaxIndex < MiGA::MiGA
60
61
  # Generate JSON String for the index.
61
62
  def to_json
62
63
  MiGA::Json.generate(
63
- { root: root.to_hash, datasets: datasets.map { |d| d.name } }
64
+ root: root.to_hash,
65
+ datasets: datasets.map(&:name)
64
66
  )
65
67
  end
66
68
 
@@ -119,27 +121,33 @@ class MiGA::TaxIndexTaxon < MiGA::MiGA
119
121
  ##
120
122
  # Get the number of datasets in the taxon (including children).
121
123
  def datasets_count
122
- children.map { |it| it.datasets_count }.reduce(datasets.size, :+)
124
+ children.map(&:datasets_count).reduce(datasets.size, :+)
123
125
  end
124
126
 
125
127
  ##
126
128
  # Get all the datasets in the taxon (including children).
127
129
  def all_datasets
128
- children.map { |it| it.datasets }.reduce(datasets, :+)
130
+ children.map(&:datasets).reduce(datasets, :+)
129
131
  end
130
132
 
131
133
  ##
132
134
  # JSON String of the taxon.
133
135
  def to_json(*a)
134
- { str: tax_str, datasets: datasets.map { |d| d.name },
135
- children: children }.to_json(a)
136
+ {
137
+ str: tax_str,
138
+ datasets: datasets.map(&:name),
139
+ children: children
140
+ }.to_json(a)
136
141
  end
137
142
 
138
143
  ##
139
144
  # Hash representation of the taxon.
140
145
  def to_hash
141
- { str: tax_str, datasets: datasets.map { |d| d.name },
142
- children: children.map { |it| it.to_hash } }
146
+ {
147
+ str: tax_str,
148
+ datasets: datasets.map(&:name),
149
+ children: children.map(&:to_hash)
150
+ }
143
151
  end
144
152
 
145
153
  ##
@@ -8,7 +8,7 @@ module MiGA
8
8
  # - Float representing the major.minor version.
9
9
  # - Integer representing gem releases of the current version.
10
10
  # - Integer representing minor changes that require new version number.
11
- VERSION = [0.7, 20, 0]
11
+ VERSION = [0.7, 20, 1]
12
12
 
13
13
  ##
14
14
  # Nickname for the current major.minor version.
@@ -16,7 +16,7 @@ module MiGA
16
16
 
17
17
  ##
18
18
  # Date of the current gem release.
19
- VERSION_DATE = Date.new(2021, 1, 7)
19
+ VERSION_DATE = Date.new(2021, 1, 10)
20
20
 
21
21
  ##
22
22
  # Reference of MiGA.
@@ -72,4 +72,34 @@ class CommonTest < Test::Unit::TestCase
72
72
  assert_not_predicate('C3-PO', :miga_name?)
73
73
  assert_equal("123\n1\n", '1231'.wrap_width(3))
74
74
  end
75
+
76
+ def test_advance
77
+ m = MiGA::MiGA.new
78
+
79
+ # Check advance when missing total
80
+ o = capture_stderr { m.advance('x', 0) }.string
81
+ assert_match(/\] x *\r/, o)
82
+
83
+ # Initialize advance
84
+ o = capture_stderr { m.advance('x', 0, 10) }.string
85
+ assert_match(/\] x 0\.0% \(0\/10\) *\r/, o)
86
+
87
+ # Insufficient data for prediction
88
+ sleep(1)
89
+ o = capture_stderr { m.advance('x', 1, 10) }.string
90
+ assert_match(/\] x 10\.0% \(1\/10\) *\r/, o)
91
+
92
+ # Predict time
93
+ sleep(1)
94
+ o = capture_stderr { m.advance('x', 2, 10) }.string
95
+ assert_match(/\] x 20\.0% \(2\/10\) [7-9]s left *\r/, o)
96
+ end
97
+
98
+ def test_num_suffix
99
+ m = MiGA::MiGA.new
100
+ assert_equal('12', m.num_suffix(12))
101
+ assert_equal('1.5K', m.num_suffix(1.5e3))
102
+ assert_equal('1.0M', m.num_suffix(1024**2 + 1, true))
103
+ assert_equal('1.1G', m.num_suffix(1024**3))
104
+ end
75
105
  end
@@ -48,7 +48,10 @@ class DaemonTest < Test::Unit::TestCase
48
48
  end
49
49
  assert_match(/Queueing #{ds.name}:d/, out.string)
50
50
  assert_equal(1, d.jobs_to_run.size)
51
- assert_equal('echo project0:d:ds1 >/dev/null', d.jobs_to_run.first[:cmd])
51
+ assert_equal(
52
+ 'echo project0:d:ds1 >/dev/null',
53
+ d.job_cmd(d.jobs_to_run.first)
54
+ )
52
55
  assert_equal(d.jobs_to_run.first, d.get_job(:d, ds))
53
56
  end
54
57
 
@@ -335,4 +338,17 @@ class DaemonTest < Test::Unit::TestCase
335
338
  capture_stderr { d.in_loop }
336
339
  assert_equal([], d.jobs_running)
337
340
  end
341
+
342
+ def test_show_log
343
+ d = daemon
344
+ assert(d.show_log?)
345
+ d.runopts(:show_log, false)
346
+ assert(!d.show_log?)
347
+ d.show_log!
348
+ assert(d.show_log?)
349
+ assert_equal($stderr, d.logfh)
350
+ d.show_summary!
351
+ assert(!d.show_log?)
352
+ assert_not_equal($stderr, d.logfh)
353
+ end
338
354
  end
@@ -35,4 +35,30 @@ class TaxIndexTest < Test::Unit::TestCase
35
35
  ti = MiGA::TaxIndex.new
36
36
  assert_equal("root:biota: 0\n", ti.to_tab)
37
37
  end
38
+
39
+ def test_tax_index_taxon
40
+ taxon = MiGA::TaxIndexTaxon.new(:root, 'biota')
41
+ assert_empty(taxon.datasets)
42
+ assert_equal('root:biota', taxon.to_hash[:str])
43
+ assert_equal(
44
+ '{"str":"root:biota","datasets":[],"children":[]}',
45
+ taxon.to_json
46
+ )
47
+ assert_empty(taxon.all_datasets)
48
+ assert_equal(0, taxon.datasets_count)
49
+ end
50
+
51
+ def test_taxa_by_rank
52
+ initialize_miga_home
53
+ d = dataset
54
+ d.metadata[:tax] = MiGA::Taxonomy.new('k:Fantasia g:Unicornia')
55
+
56
+ # Empty
57
+ ti = MiGA::TaxIndex.new
58
+ assert_empty(ti.taxa_by_rank(:genus))
59
+
60
+ # Unicorn
61
+ ti << d
62
+ assert_equal('Unicornia', ti.taxa_by_rank(:genus).first.name)
63
+ end
38
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miga-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.20.0
4
+ version: 0.7.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis M. Rodriguez-R
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-07 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daemons