rbbt-util 5.44.1 → 6.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rbbt +67 -90
- data/etc/app.d/base.rb +2 -2
- data/etc/app.d/semaphores.rb +3 -3
- data/lib/rbbt/annotations/annotated_array.rb +207 -207
- data/lib/rbbt/annotations/refactor.rb +27 -0
- data/lib/rbbt/annotations/util.rb +282 -282
- data/lib/rbbt/annotations.rb +343 -320
- data/lib/rbbt/association/database.rb +200 -225
- data/lib/rbbt/association/index.rb +294 -291
- data/lib/rbbt/association/item.rb +227 -227
- data/lib/rbbt/association/open.rb +35 -34
- data/lib/rbbt/association/util.rb +0 -169
- data/lib/rbbt/association.rb +2 -4
- data/lib/rbbt/entity/identifiers.rb +119 -118
- data/lib/rbbt/entity/refactor.rb +12 -0
- data/lib/rbbt/entity.rb +319 -315
- data/lib/rbbt/hpc/batch.rb +72 -53
- data/lib/rbbt/hpc/lsf.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/batches.rb +2 -2
- data/lib/rbbt/hpc/orchestrate/chains.rb +25 -5
- data/lib/rbbt/hpc/orchestrate/rules.rb +2 -2
- data/lib/rbbt/hpc/orchestrate.rb +19 -13
- data/lib/rbbt/hpc/slurm.rb +18 -18
- data/lib/rbbt/knowledge_base/entity.rb +13 -5
- data/lib/rbbt/knowledge_base/query.rb +2 -2
- data/lib/rbbt/knowledge_base/registry.rb +32 -31
- data/lib/rbbt/knowledge_base/traverse.rb +1 -1
- data/lib/rbbt/knowledge_base.rb +1 -1
- data/lib/rbbt/monitor.rb +36 -25
- data/lib/rbbt/persist/refactor.rb +166 -0
- data/lib/rbbt/persist/tsv/tokyocabinet.rb +105 -105
- data/lib/rbbt/persist/tsv.rb +187 -185
- data/lib/rbbt/persist.rb +556 -551
- data/lib/rbbt/refactor.rb +20 -0
- data/lib/rbbt/resource/path/refactor.rb +178 -0
- data/lib/rbbt/resource/path.rb +317 -497
- data/lib/rbbt/resource/util.rb +0 -48
- data/lib/rbbt/resource.rb +3 -390
- data/lib/rbbt/tsv/accessor.rb +2 -838
- data/lib/rbbt/tsv/attach.rb +303 -299
- data/lib/rbbt/tsv/change_id.rb +244 -245
- data/lib/rbbt/tsv/csv.rb +87 -85
- data/lib/rbbt/tsv/dumper.rb +2 -100
- data/lib/rbbt/tsv/excel.rb +26 -24
- data/lib/rbbt/tsv/field_index.rb +4 -1
- data/lib/rbbt/tsv/filter.rb +3 -2
- data/lib/rbbt/tsv/index.rb +2 -284
- data/lib/rbbt/tsv/manipulate.rb +750 -747
- data/lib/rbbt/tsv/marshal.rb +3 -3
- data/lib/rbbt/tsv/matrix.rb +2 -2
- data/lib/rbbt/tsv/parallel/through.rb +2 -1
- data/lib/rbbt/tsv/parallel/traverse.rb +783 -781
- data/lib/rbbt/tsv/parser.rb +678 -678
- data/lib/rbbt/tsv/refactor.rb +195 -0
- data/lib/rbbt/tsv/stream.rb +253 -251
- data/lib/rbbt/tsv/util.rb +420 -420
- data/lib/rbbt/tsv.rb +210 -208
- data/lib/rbbt/util/R/eval.rb +4 -4
- data/lib/rbbt/util/R/plot.rb +62 -166
- data/lib/rbbt/util/R.rb +21 -18
- data/lib/rbbt/util/cmd.rb +2 -318
- data/lib/rbbt/util/color.rb +269 -269
- data/lib/rbbt/util/colorize.rb +89 -89
- data/lib/rbbt/util/concurrency/processes/refactor.rb +22 -0
- data/lib/rbbt/util/concurrency/processes/worker.rb +2 -2
- data/lib/rbbt/util/concurrency/processes.rb +389 -386
- data/lib/rbbt/util/config.rb +169 -167
- data/lib/rbbt/util/iruby.rb +20 -0
- data/lib/rbbt/util/log/progress/report.rb +241 -241
- data/lib/rbbt/util/log/progress/util.rb +99 -99
- data/lib/rbbt/util/log/progress.rb +102 -102
- data/lib/rbbt/util/log/refactor.rb +49 -0
- data/lib/rbbt/util/log.rb +486 -532
- data/lib/rbbt/util/migrate.rb +1 -1
- data/lib/rbbt/util/misc/concurrent_stream.rb +248 -246
- data/lib/rbbt/util/misc/development.rb +12 -11
- data/lib/rbbt/util/misc/exceptions.rb +117 -112
- data/lib/rbbt/util/misc/format.rb +2 -230
- data/lib/rbbt/util/misc/indiferent_hash.rb +2 -107
- data/lib/rbbt/util/misc/inspect.rb +2 -476
- data/lib/rbbt/util/misc/lock.rb +109 -106
- data/lib/rbbt/util/misc/omics.rb +9 -1
- data/lib/rbbt/util/misc/pipes.rb +765 -793
- data/lib/rbbt/util/misc/refactor.rb +20 -0
- data/lib/rbbt/util/misc/ssw.rb +27 -17
- data/lib/rbbt/util/misc/system.rb +0 -15
- data/lib/rbbt/util/misc.rb +39 -20
- data/lib/rbbt/util/named_array/refactor.rb +4 -0
- data/lib/rbbt/util/named_array.rb +3 -220
- data/lib/rbbt/util/open/refactor.rb +7 -0
- data/lib/rbbt/util/open.rb +3 -857
- data/lib/rbbt/util/procpath.rb +6 -6
- data/lib/rbbt/util/python/paths.rb +27 -0
- data/lib/rbbt/util/python/run.rb +115 -0
- data/lib/rbbt/util/python/script.rb +110 -0
- data/lib/rbbt/util/python/util.rb +3 -3
- data/lib/rbbt/util/python.rb +22 -81
- data/lib/rbbt/util/semaphore.rb +152 -148
- data/lib/rbbt/util/simpleopt.rb +9 -8
- data/lib/rbbt/util/ssh/refactor.rb +19 -0
- data/lib/rbbt/util/ssh.rb +122 -118
- data/lib/rbbt/util/tar.rb +117 -115
- data/lib/rbbt/util/tmpfile.rb +69 -67
- data/lib/rbbt/util/version.rb +2 -0
- data/lib/rbbt/workflow/refactor/entity.rb +11 -0
- data/lib/rbbt/workflow/refactor/export.rb +66 -0
- data/lib/rbbt/workflow/refactor/inputs.rb +24 -0
- data/lib/rbbt/workflow/refactor/recursive.rb +64 -0
- data/lib/rbbt/workflow/refactor/task_info.rb +65 -0
- data/lib/rbbt/workflow/refactor.rb +153 -0
- data/lib/rbbt/workflow/remote_workflow/driver/ssh.rb +55 -32
- data/lib/rbbt/workflow/remote_workflow/remote_step/rest.rb +3 -1
- data/lib/rbbt/workflow/remote_workflow/remote_step/ssh.rb +14 -5
- data/lib/rbbt/workflow/remote_workflow/remote_step.rb +19 -7
- data/lib/rbbt/workflow/remote_workflow.rb +6 -1
- data/lib/rbbt/workflow/step/run.rb +766 -766
- data/lib/rbbt/workflow/step/save_load_inputs.rb +254 -254
- data/lib/rbbt/workflow/step.rb +2 -362
- data/lib/rbbt/workflow/task.rb +118 -118
- data/lib/rbbt/workflow/usage.rb +289 -287
- data/lib/rbbt/workflow/util/archive.rb +6 -5
- data/lib/rbbt/workflow/util/data.rb +1 -1
- data/lib/rbbt/workflow/util/orchestrator.rb +249 -246
- data/lib/rbbt/workflow/util/trace.rb +79 -44
- data/lib/rbbt/workflow.rb +4 -882
- data/lib/rbbt-util.rb +21 -13
- data/lib/rbbt.rb +16 -3
- data/python/rbbt/__init__.py +19 -1
- data/share/Rlib/plot.R +37 -37
- data/share/Rlib/svg.R +22 -5
- data/share/install/software/lib/install_helpers +1 -1
- data/share/rbbt_commands/hpc/list +2 -3
- data/share/rbbt_commands/hpc/orchestrate +4 -4
- data/share/rbbt_commands/hpc/tail +2 -0
- data/share/rbbt_commands/hpc/task +10 -7
- data/share/rbbt_commands/lsf/list +2 -3
- data/share/rbbt_commands/lsf/orchestrate +4 -4
- data/share/rbbt_commands/lsf/tail +2 -0
- data/share/rbbt_commands/lsf/task +10 -7
- data/share/rbbt_commands/migrate +1 -1
- data/share/rbbt_commands/pbs/list +2 -3
- data/share/rbbt_commands/pbs/orchestrate +4 -4
- data/share/rbbt_commands/pbs/tail +2 -0
- data/share/rbbt_commands/pbs/task +10 -7
- data/share/rbbt_commands/resource/produce +8 -1
- data/share/rbbt_commands/slurm/list +2 -3
- data/share/rbbt_commands/slurm/orchestrate +4 -4
- data/share/rbbt_commands/slurm/tail +2 -0
- data/share/rbbt_commands/slurm/task +10 -7
- data/share/rbbt_commands/system/clean +5 -5
- data/share/rbbt_commands/system/status +5 -5
- data/share/rbbt_commands/tsv/get +2 -3
- data/share/rbbt_commands/tsv/info +10 -13
- data/share/rbbt_commands/tsv/keys +18 -14
- data/share/rbbt_commands/tsv/slice +2 -2
- data/share/rbbt_commands/tsv/transpose +6 -2
- data/share/rbbt_commands/workflow/info +20 -24
- data/share/rbbt_commands/workflow/list +1 -1
- data/share/rbbt_commands/workflow/prov +20 -13
- data/share/rbbt_commands/workflow/server +11 -1
- data/share/rbbt_commands/workflow/task +76 -71
- data/share/rbbt_commands/workflow/write_info +26 -9
- data/share/software/opt/ssw/ssw.c +861 -0
- data/share/software/opt/ssw/ssw.h +130 -0
- data/share/workflow_config.ru +3 -3
- metadata +40 -2
data/lib/rbbt/workflow/step.rb
CHANGED
@@ -1,362 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rbbt/util/log'
|
4
|
-
require 'rbbt/util/semaphore'
|
5
|
-
require 'rbbt/workflow/step/accessor'
|
6
|
-
require 'rbbt/workflow/step/produce'
|
7
|
-
require 'rbbt/workflow/step/status'
|
8
|
-
require 'rbbt/workflow/step/info'
|
9
|
-
require 'rbbt/workflow/step/save_load_inputs'
|
10
|
-
|
11
|
-
class Step
|
12
|
-
RBBT_DEBUG_CLEAN = ENV["RBBT_DEBUG_CLEAN"] == 'true'
|
13
|
-
|
14
|
-
class << self
|
15
|
-
attr_accessor :lock_dir
|
16
|
-
|
17
|
-
def lock_dir
|
18
|
-
@lock_dir ||= begin
|
19
|
-
dir = Rbbt.tmp.step_info_locks.find
|
20
|
-
FileUtils.mkdir_p dir unless Open.exists? dir
|
21
|
-
dir
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def clean_name
|
27
|
-
@clean_name ||= begin
|
28
|
-
info[:clean_name] || path.sub(/_[a-z0-9]{32}/, '')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def initialize(path, task = nil, inputs = nil, dependencies = nil, bindings = nil, clean_name = nil, &block)
|
34
|
-
path = Path.setup(Misc.sanitize_filename(path)) if String === path
|
35
|
-
path = path.call if Proc === path
|
36
|
-
|
37
|
-
task = block if block_given?
|
38
|
-
|
39
|
-
@path = path
|
40
|
-
@task = task
|
41
|
-
@bindings = bindings
|
42
|
-
@dependencies = case
|
43
|
-
when dependencies.nil?
|
44
|
-
[]
|
45
|
-
when Array === dependencies
|
46
|
-
dependencies
|
47
|
-
else
|
48
|
-
[dependencies]
|
49
|
-
end
|
50
|
-
@mutex = Mutex.new
|
51
|
-
@info_mutex = Mutex.new
|
52
|
-
@inputs = inputs
|
53
|
-
NamedArray.setup @inputs, task.inputs.collect{|s| s.to_s} if task and task.respond_to? :inputs and task.inputs
|
54
|
-
end
|
55
|
-
|
56
|
-
def workflow
|
57
|
-
@workflow ||= begin
|
58
|
-
wf = info[:workflow]
|
59
|
-
wf = nil if wf == ""
|
60
|
-
wf ||= @task.workflow if @task && @task.respond_to?(:workflow)
|
61
|
-
wf ||= path.split("/")[-3]
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
def inputs
|
68
|
-
return @inputs if NamedArray === @inputs
|
69
|
-
|
70
|
-
load_inputs_from_info if @inputs.nil?
|
71
|
-
|
72
|
-
task_inputs = task.respond_to?(:inputs) ? task.inputs : nil
|
73
|
-
NamedArray.setup(@inputs, task_inputs) unless NamedArray === @inputs
|
74
|
-
|
75
|
-
@inputs || []
|
76
|
-
end
|
77
|
-
|
78
|
-
def copy_files_dir
|
79
|
-
if File.symlink?(self.files_dir)
|
80
|
-
begin
|
81
|
-
realpath = Open.realpath(self.files_dir)
|
82
|
-
Open.rm self.files_dir
|
83
|
-
Open.cp realpath, self.files_dir
|
84
|
-
rescue
|
85
|
-
Log.warn "Copy files_dir for #{self.workflow_short_path}: " + $!.message
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def recursive_inputs(connected = false)
|
91
|
-
if NamedArray === inputs
|
92
|
-
i = {}
|
93
|
-
inputs.zip(inputs.fields).each do |v,f|
|
94
|
-
i[f] = v
|
95
|
-
end
|
96
|
-
else
|
97
|
-
i = {}
|
98
|
-
end
|
99
|
-
rec_dependencies(connected).each do |dep|
|
100
|
-
next unless NamedArray === dep.inputs
|
101
|
-
|
102
|
-
dep.inputs.zip(dep.inputs.fields).each do |v,f|
|
103
|
-
if i.include?(f) && i[f] != v
|
104
|
-
next
|
105
|
-
#Log.debug "Variable '#{f}' reused with different values: #{[Misc.fingerprint(i[f]), Misc.fingerprint(v)] * " <-> "}"
|
106
|
-
else
|
107
|
-
i[f] = v
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
dep.archived_inputs.each do |k,v|
|
112
|
-
i[k] = v unless i.include? k
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
self.archived_inputs.each do |k,v|
|
117
|
-
i[k] = v unless i.include? k
|
118
|
-
end
|
119
|
-
|
120
|
-
#dependencies.each do |dep|
|
121
|
-
# di = dep.recursive_inputs
|
122
|
-
# next unless NamedArray === di
|
123
|
-
# di.fields.zip(di).each do |k,v|
|
124
|
-
# i[k] = v unless i.include? k
|
125
|
-
# end
|
126
|
-
#end
|
127
|
-
|
128
|
-
v = i.values
|
129
|
-
NamedArray.setup v, i.keys
|
130
|
-
v
|
131
|
-
end
|
132
|
-
|
133
|
-
|
134
|
-
def path
|
135
|
-
if Proc === @path
|
136
|
-
@path = Path.setup(Misc.sanitize_filename(@path.call))
|
137
|
-
else
|
138
|
-
@path
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
class << self
|
143
|
-
attr_accessor :log_relay_step
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
# May be deprecated: This is no loger used
|
148
|
-
def relay_log(step)
|
149
|
-
return self if self.task_name.nil?
|
150
|
-
|
151
|
-
if not self.respond_to? :original_log
|
152
|
-
class << self
|
153
|
-
attr_accessor :relay_step
|
154
|
-
alias original_log log
|
155
|
-
def log(status, message = nil)
|
156
|
-
self.status = status
|
157
|
-
message Log.uncolor message
|
158
|
-
relay_step.log([self.task_name.to_s, status.to_s] * ">", message.nil? ? nil : message ) unless (relay_step.done? or relay_step.error? or relay_step.aborted?)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
@relay_step = step
|
163
|
-
|
164
|
-
self
|
165
|
-
end
|
166
|
-
|
167
|
-
def prepare_result(value, description = nil, entity_info = nil)
|
168
|
-
res = case
|
169
|
-
when IO === value
|
170
|
-
begin
|
171
|
-
res = case result_type
|
172
|
-
when :array
|
173
|
-
array = []
|
174
|
-
while line = value.gets
|
175
|
-
array << line.chomp
|
176
|
-
end
|
177
|
-
array
|
178
|
-
when :tsv
|
179
|
-
begin
|
180
|
-
TSV.open(value)
|
181
|
-
rescue IOError
|
182
|
-
TSV.setup({})
|
183
|
-
end
|
184
|
-
else
|
185
|
-
value.read
|
186
|
-
end
|
187
|
-
value.join if value.respond_to? :join
|
188
|
-
res
|
189
|
-
rescue Exception
|
190
|
-
value.abort if value.respond_to? :abort
|
191
|
-
self.abort
|
192
|
-
raise $!
|
193
|
-
end
|
194
|
-
when (not defined? Entity or description.nil? or not Entity.formats.include? description)
|
195
|
-
value
|
196
|
-
when (Annotated === value and info.empty?)
|
197
|
-
value
|
198
|
-
when Annotated === value
|
199
|
-
annotations = value.annotations
|
200
|
-
entity_info ||= begin
|
201
|
-
entity_info = info.dup
|
202
|
-
entity_info.merge! info[:inputs] if info[:inputs]
|
203
|
-
entity_info
|
204
|
-
end
|
205
|
-
entity_info.each do |k,v|
|
206
|
-
value.send("#{h}=", v) if annotations.include? k
|
207
|
-
end
|
208
|
-
|
209
|
-
value
|
210
|
-
else
|
211
|
-
entity_info ||= begin
|
212
|
-
entity_info = info.dup
|
213
|
-
entity_info.merge! info[:inputs] if info[:inputs]
|
214
|
-
entity_info
|
215
|
-
end
|
216
|
-
Entity.formats[description].setup(value, entity_info.merge(:format => description))
|
217
|
-
end
|
218
|
-
|
219
|
-
if Annotated === res
|
220
|
-
dep_hash = nil
|
221
|
-
res.annotations.each do |a|
|
222
|
-
a = a.to_s
|
223
|
-
varname = "@" + a
|
224
|
-
next unless res.instance_variable_get(varname).nil?
|
225
|
-
|
226
|
-
dep_hash ||= begin
|
227
|
-
h = {}
|
228
|
-
rec_dependencies.each{|dep| h[dep.task_name.to_s] ||= dep }
|
229
|
-
h
|
230
|
-
end
|
231
|
-
dep = dep_hash[a]
|
232
|
-
next if dep.nil?
|
233
|
-
res.send(a.to_s+"=", dep.load)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
res
|
238
|
-
end
|
239
|
-
|
240
|
-
|
241
|
-
def child(&block)
|
242
|
-
child_pid = Process.fork &block
|
243
|
-
children_pids = info[:children_pids]
|
244
|
-
if children_pids.nil?
|
245
|
-
children_pids = [child_pid]
|
246
|
-
else
|
247
|
-
children_pids << child_pid
|
248
|
-
end
|
249
|
-
set_info :children_pids, children_pids
|
250
|
-
child_pid
|
251
|
-
end
|
252
|
-
|
253
|
-
def cmd(*args)
|
254
|
-
all_args = *args
|
255
|
-
|
256
|
-
all_args << {} unless Hash === all_args.last
|
257
|
-
|
258
|
-
level = all_args.last[:log] || 0
|
259
|
-
level = 0 if TrueClass === level
|
260
|
-
level = 10 if FalseClass === level
|
261
|
-
level = level.to_i
|
262
|
-
|
263
|
-
all_args.last[:log] = true
|
264
|
-
all_args.last[:pipe] = true
|
265
|
-
|
266
|
-
io = CMD.cmd(*all_args)
|
267
|
-
child_pid = io.pids.first
|
268
|
-
|
269
|
-
children_pids = info[:children_pids]
|
270
|
-
if children_pids.nil?
|
271
|
-
children_pids = [child_pid]
|
272
|
-
else
|
273
|
-
children_pids << child_pid
|
274
|
-
end
|
275
|
-
set_info :children_pids, children_pids
|
276
|
-
|
277
|
-
while c = io.getc
|
278
|
-
STDERR << c if Log.severity <= level
|
279
|
-
if c == "\n"
|
280
|
-
if pid
|
281
|
-
Log.logn "STDOUT [#{pid}]: ", level
|
282
|
-
else
|
283
|
-
Log.logn "STDOUT: ", level
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
io.join
|
289
|
-
|
290
|
-
nil
|
291
|
-
end
|
292
|
-
|
293
|
-
|
294
|
-
def load
|
295
|
-
res = begin
|
296
|
-
@result = nil if IO === @result && @result.closed?
|
297
|
-
if @result && @path != @result && ! StreamArray === @result
|
298
|
-
res = @result
|
299
|
-
else
|
300
|
-
join if not done?
|
301
|
-
res = @path.exists? ? Persist.load_file(@path, result_type) : run
|
302
|
-
end
|
303
|
-
|
304
|
-
if result_description
|
305
|
-
entity_info = info.dup
|
306
|
-
# Also load entity_info in rbbt6
|
307
|
-
entity_info.merge! info[:inputs] if Hash === info[:inputs]
|
308
|
-
res = prepare_result res, result_description, entity_info
|
309
|
-
end
|
310
|
-
|
311
|
-
res
|
312
|
-
rescue IOError
|
313
|
-
if @result
|
314
|
-
@result = nil
|
315
|
-
retry
|
316
|
-
end
|
317
|
-
raise $!
|
318
|
-
ensure
|
319
|
-
@result = nil if IO === @result
|
320
|
-
end
|
321
|
-
|
322
|
-
res
|
323
|
-
end
|
324
|
-
|
325
|
-
def update
|
326
|
-
if dirty?
|
327
|
-
dependencies.collect{|d| d.update } if dependencies
|
328
|
-
clean
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
def writable?
|
333
|
-
Open.writable?(self.path) && Open.writable?(self.info_file)
|
334
|
-
end
|
335
|
-
|
336
|
-
def recursive_clean
|
337
|
-
dependencies.each do |step|
|
338
|
-
step.recursive_clean
|
339
|
-
end if dependencies
|
340
|
-
clean if Open.exists?(self.info_file)
|
341
|
-
self
|
342
|
-
end
|
343
|
-
|
344
|
-
def step(name)
|
345
|
-
@steps ||= {}
|
346
|
-
@steps[name] ||= begin
|
347
|
-
name = name.to_sym
|
348
|
-
deps = rec_dependencies.select{|step|
|
349
|
-
step.task_name && step.task_name.to_sym == name
|
350
|
-
}
|
351
|
-
raise "Dependency step not found: #{ name }" if deps.empty?
|
352
|
-
if (deps & self.dependencies).any?
|
353
|
-
(deps & self.dependencies).last
|
354
|
-
else
|
355
|
-
deps.last
|
356
|
-
end
|
357
|
-
end
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
require 'rbbt/workflow/step/run'
|
362
|
-
require 'rbbt/workflow/step/accessor'
|
1
|
+
require_relative '../refactor'
|
2
|
+
Rbbt.require_instead 'scout/workflow/step'
|
data/lib/rbbt/workflow/task.rb
CHANGED
@@ -1,118 +1,118 @@
|
|
1
|
-
require 'rbbt/util/misc'
|
2
|
-
require 'rbbt/persist'
|
3
|
-
|
4
|
-
module Task
|
5
|
-
attr_accessor :inputs, :input_types, :result_type, :input_defaults, :input_descriptions, :input_options, :required_inputs, :description, :name, :result_description, :extension, :workflow, :resumable
|
6
|
-
|
7
|
-
def self.setup(options = {}, &block)
|
8
|
-
block.extend Task
|
9
|
-
options = IndiferentHash.setup options
|
10
|
-
block.singleton_methods.
|
11
|
-
select{|method| method.to_s[-1] != "="[0]}.each{|method|
|
12
|
-
if block.respond_to?(method.to_s + "=") and options.include? method.to_sym
|
13
|
-
block.send(method.to_s + '=', options[method.to_sym])
|
14
|
-
end
|
15
|
-
}
|
16
|
-
block
|
17
|
-
end
|
18
|
-
|
19
|
-
def parse_description
|
20
|
-
if description =~ /\n\n/
|
21
|
-
short_description, rest = description.match(/(.*?)\n\n(.*)/).values_at 1, 2
|
22
|
-
else
|
23
|
-
short_description = description
|
24
|
-
rest = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
if rest.nil?
|
28
|
-
long_description = ""
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def take_input_values(input_values)
|
33
|
-
return [] if @inputs.nil?
|
34
|
-
values = []
|
35
|
-
defaults = IndiferentHash.setup(@input_defaults || {})
|
36
|
-
@inputs.each do |input|
|
37
|
-
value = input_values[input]
|
38
|
-
value = defaults[input] if value.nil?
|
39
|
-
values << value
|
40
|
-
end
|
41
|
-
values
|
42
|
-
end
|
43
|
-
|
44
|
-
def exec(*args)
|
45
|
-
case
|
46
|
-
when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first)
|
47
|
-
self.call *take_input_values(IndiferentHash.setup(args.first))
|
48
|
-
else
|
49
|
-
self.call *args
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def exec_in(object, *args)
|
54
|
-
case
|
55
|
-
when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first)
|
56
|
-
object.instance_exec *IndiferentHash.setup(args.first).values_at(*inputs), &self
|
57
|
-
else
|
58
|
-
object.instance_exec *args, &self
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def persist_exec(filename, *args)
|
63
|
-
Persist.persist "Task", @persistence_type, :file => filename do
|
64
|
-
exec *args
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def persist_exec_in(filename, *args)
|
69
|
-
Persist.persist "Task", @persistence_type, :file => filename do
|
70
|
-
exec_in *args
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.dep_inputs(deps, workflow = nil)
|
75
|
-
seen = []
|
76
|
-
task_inputs = {}
|
77
|
-
deps.each do |dep|
|
78
|
-
if Symbol === dep
|
79
|
-
wf, task = [workflow, workflow.tasks[dep.to_sym]]
|
80
|
-
elsif Array === dep and dep.first
|
81
|
-
wf, task_name, options = dep
|
82
|
-
options, task_name = task_name, nil if Hash === task_name
|
83
|
-
options, wf = wf, nil if Hash === wf
|
84
|
-
task_name, wf = wf, workflow if task_name.nil? and Symbol === wf or String === wf
|
85
|
-
next if task_name.nil?
|
86
|
-
task = wf.tasks[task_name.to_sym]
|
87
|
-
else
|
88
|
-
next
|
89
|
-
end
|
90
|
-
|
91
|
-
task_name ||= task.name
|
92
|
-
|
93
|
-
maps = (Array === dep and Hash === dep.last) ? dep.last.keys : []
|
94
|
-
raise "Dependency task not found: #{dep}" if task.nil?
|
95
|
-
next if seen.include? [wf, task_name, maps]
|
96
|
-
|
97
|
-
task.workflow = wf if wf
|
98
|
-
|
99
|
-
seen << [wf, task_name, maps]
|
100
|
-
new_inputs = task.inputs - maps
|
101
|
-
next unless new_inputs.any?
|
102
|
-
if task_inputs[task].nil?
|
103
|
-
task_inputs[task] = new_inputs
|
104
|
-
else
|
105
|
-
task_inputs[task] = (task_inputs[task] + new_inputs).uniq
|
106
|
-
end
|
107
|
-
end
|
108
|
-
task_inputs
|
109
|
-
end
|
110
|
-
|
111
|
-
def dep_inputs(deps, workflow = nil)
|
112
|
-
return {} if deps.empty?
|
113
|
-
task_inputs = Task.dep_inputs deps, workflow
|
114
|
-
task_inputs.each do |task, inputs|
|
115
|
-
inputs.replace (inputs - self.inputs)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
1
|
+
#require 'rbbt/util/misc'
|
2
|
+
#require 'rbbt/persist'
|
3
|
+
#
|
4
|
+
#module Task
|
5
|
+
# attr_accessor :inputs, :input_types, :result_type, :input_defaults, :input_descriptions, :input_options, :required_inputs, :description, :name, :result_description, :extension, :workflow, :resumable
|
6
|
+
#
|
7
|
+
# def self.setup(options = {}, &block)
|
8
|
+
# block.extend Task
|
9
|
+
# options = IndiferentHash.setup options
|
10
|
+
# block.singleton_methods.
|
11
|
+
# select{|method| method.to_s[-1] != "="[0]}.each{|method|
|
12
|
+
# if block.respond_to?(method.to_s + "=") and options.include? method.to_sym
|
13
|
+
# block.send(method.to_s + '=', options[method.to_sym])
|
14
|
+
# end
|
15
|
+
# }
|
16
|
+
# block
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def parse_description
|
20
|
+
# if description =~ /\n\n/
|
21
|
+
# short_description, rest = description.match(/(.*?)\n\n(.*)/).values_at 1, 2
|
22
|
+
# else
|
23
|
+
# short_description = description
|
24
|
+
# rest = nil
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# if rest.nil?
|
28
|
+
# long_description = ""
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# def take_input_values(input_values)
|
33
|
+
# return [] if @inputs.nil?
|
34
|
+
# values = []
|
35
|
+
# defaults = IndiferentHash.setup(@input_defaults || {})
|
36
|
+
# @inputs.each do |input|
|
37
|
+
# value = input_values[input]
|
38
|
+
# value = defaults[input] if value.nil?
|
39
|
+
# values << value
|
40
|
+
# end
|
41
|
+
# values
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# def exec(*args)
|
45
|
+
# case
|
46
|
+
# when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first)
|
47
|
+
# self.call *take_input_values(IndiferentHash.setup(args.first))
|
48
|
+
# else
|
49
|
+
# self.call *args
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
#
|
53
|
+
# def exec_in(object, *args)
|
54
|
+
# case
|
55
|
+
# when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first)
|
56
|
+
# object.instance_exec *IndiferentHash.setup(args.first).values_at(*inputs), &self
|
57
|
+
# else
|
58
|
+
# object.instance_exec *args, &self
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# def persist_exec(filename, *args)
|
63
|
+
# Persist.persist "Task", @persistence_type, :file => filename do
|
64
|
+
# exec *args
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# def persist_exec_in(filename, *args)
|
69
|
+
# Persist.persist "Task", @persistence_type, :file => filename do
|
70
|
+
# exec_in *args
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
#
|
74
|
+
# def self.dep_inputs(deps, workflow = nil)
|
75
|
+
# seen = []
|
76
|
+
# task_inputs = {}
|
77
|
+
# deps.each do |dep|
|
78
|
+
# if Symbol === dep
|
79
|
+
# wf, task = [workflow, workflow.tasks[dep.to_sym]]
|
80
|
+
# elsif Array === dep and dep.first
|
81
|
+
# wf, task_name, options = dep
|
82
|
+
# options, task_name = task_name, nil if Hash === task_name
|
83
|
+
# options, wf = wf, nil if Hash === wf
|
84
|
+
# task_name, wf = wf, workflow if task_name.nil? and Symbol === wf or String === wf
|
85
|
+
# next if task_name.nil?
|
86
|
+
# task = wf.tasks[task_name.to_sym]
|
87
|
+
# else
|
88
|
+
# next
|
89
|
+
# end
|
90
|
+
#
|
91
|
+
# task_name ||= task.name
|
92
|
+
#
|
93
|
+
# maps = (Array === dep and Hash === dep.last) ? dep.last.keys : []
|
94
|
+
# raise "Dependency task not found: #{dep}" if task.nil?
|
95
|
+
# next if seen.include? [wf, task_name, maps]
|
96
|
+
#
|
97
|
+
# task.workflow = wf if wf
|
98
|
+
#
|
99
|
+
# seen << [wf, task_name, maps]
|
100
|
+
# new_inputs = task.inputs - maps
|
101
|
+
# next unless new_inputs.any?
|
102
|
+
# if task_inputs[task].nil?
|
103
|
+
# task_inputs[task] = new_inputs
|
104
|
+
# else
|
105
|
+
# task_inputs[task] = (task_inputs[task] + new_inputs).uniq
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
# task_inputs
|
109
|
+
# end
|
110
|
+
#
|
111
|
+
# def dep_inputs(deps, workflow = nil)
|
112
|
+
# return {} if deps.empty?
|
113
|
+
# task_inputs = Task.dep_inputs deps, workflow
|
114
|
+
# task_inputs.each do |task, inputs|
|
115
|
+
# inputs.replace (inputs - self.inputs)
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
#end
|