scout-gear 10.4.0 → 10.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +100 -656
  3. data/Rakefile +1 -0
  4. data/VERSION +1 -1
  5. data/bin/scout +1 -3
  6. data/lib/scout/association/fields.rb +170 -0
  7. data/lib/scout/association/index.rb +229 -0
  8. data/lib/scout/association/item.rb +227 -0
  9. data/lib/scout/association/util.rb +7 -0
  10. data/lib/scout/association.rb +100 -0
  11. data/lib/scout/entity/format.rb +62 -0
  12. data/lib/scout/entity/identifiers.rb +111 -0
  13. data/lib/scout/entity/object.rb +20 -0
  14. data/lib/scout/entity/property.rb +165 -0
  15. data/lib/scout/entity.rb +40 -0
  16. data/lib/scout/offsite/step.rb +2 -2
  17. data/lib/scout/{tsv/persist → persist/engine}/fix_width_table.rb +25 -33
  18. data/lib/scout/persist/engine/packed_index.rb +100 -0
  19. data/lib/scout/persist/engine/sharder.rb +219 -0
  20. data/lib/scout/{tsv/persist → persist/engine}/tkrzw.rb +0 -17
  21. data/lib/scout/{tsv/persist → persist/engine}/tokyocabinet.rb +55 -31
  22. data/lib/scout/persist/engine.rb +4 -0
  23. data/lib/scout/{tsv/persist/adapter.rb → persist/tsv/adapter/base.rb} +80 -51
  24. data/lib/scout/persist/tsv/adapter/fix_width_table.rb +106 -0
  25. data/lib/scout/persist/tsv/adapter/packed_index.rb +95 -0
  26. data/lib/scout/persist/tsv/adapter/sharder.rb +54 -0
  27. data/lib/scout/persist/tsv/adapter/tkrzw.rb +18 -0
  28. data/lib/scout/persist/tsv/adapter/tokyocabinet.rb +65 -0
  29. data/lib/scout/persist/tsv/adapter.rb +6 -0
  30. data/lib/scout/{tsv/persist → persist/tsv}/serialize.rb +5 -0
  31. data/lib/scout/persist/tsv.rb +107 -0
  32. data/lib/scout/tsv/annotation/repo.rb +83 -0
  33. data/lib/scout/tsv/annotation.rb +169 -0
  34. data/lib/scout/tsv/attach.rb +95 -19
  35. data/lib/scout/tsv/change_id/translate.rb +148 -0
  36. data/lib/scout/tsv/change_id.rb +3 -0
  37. data/lib/scout/tsv/csv.rb +85 -0
  38. data/lib/scout/tsv/dumper.rb +113 -25
  39. data/lib/scout/tsv/entity.rb +5 -0
  40. data/lib/scout/tsv/index.rb +88 -36
  41. data/lib/scout/tsv/open.rb +21 -8
  42. data/lib/scout/tsv/parser.rb +153 -90
  43. data/lib/scout/tsv/path.rb +7 -2
  44. data/lib/scout/tsv/stream.rb +48 -6
  45. data/lib/scout/tsv/transformer.rb +4 -3
  46. data/lib/scout/tsv/traverse.rb +26 -18
  47. data/lib/scout/tsv/util/process.rb +7 -0
  48. data/lib/scout/tsv/util/reorder.rb +25 -15
  49. data/lib/scout/tsv/util/select.rb +9 -1
  50. data/lib/scout/tsv/util/sort.rb +90 -2
  51. data/lib/scout/tsv/util/unzip.rb +56 -0
  52. data/lib/scout/tsv/util.rb +52 -5
  53. data/lib/scout/tsv.rb +45 -27
  54. data/lib/scout/work_queue/socket.rb +8 -0
  55. data/lib/scout/work_queue/worker.rb +22 -5
  56. data/lib/scout/work_queue.rb +38 -24
  57. data/lib/scout/workflow/definition.rb +11 -10
  58. data/lib/scout/workflow/deployment/orchestrator.rb +20 -3
  59. data/lib/scout/workflow/deployment/trace.rb +205 -0
  60. data/lib/scout/workflow/deployment.rb +1 -0
  61. data/lib/scout/workflow/documentation.rb +1 -1
  62. data/lib/scout/workflow/step/archive.rb +42 -0
  63. data/lib/scout/workflow/step/children.rb +51 -0
  64. data/lib/scout/workflow/step/config.rb +1 -1
  65. data/lib/scout/workflow/step/dependencies.rb +24 -7
  66. data/lib/scout/workflow/step/file.rb +19 -0
  67. data/lib/scout/workflow/step/info.rb +37 -9
  68. data/lib/scout/workflow/step/progress.rb +11 -2
  69. data/lib/scout/workflow/step/status.rb +8 -1
  70. data/lib/scout/workflow/step.rb +80 -25
  71. data/lib/scout/workflow/task/dependencies.rb +4 -1
  72. data/lib/scout/workflow/task/inputs.rb +91 -41
  73. data/lib/scout/workflow/task.rb +54 -57
  74. data/lib/scout/workflow/usage.rb +1 -1
  75. data/lib/scout/workflow/util.rb +4 -0
  76. data/lib/scout/workflow.rb +110 -13
  77. data/lib/scout-gear.rb +2 -0
  78. data/lib/scout.rb +0 -1
  79. data/scout-gear.gemspec +80 -23
  80. data/scout_commands/rbbt +2 -0
  81. data/test/data/person/brothers +4 -0
  82. data/test/data/person/identifiers +10 -0
  83. data/test/data/person/marriages +3 -0
  84. data/test/data/person/parents +6 -0
  85. data/test/scout/association/test_fields.rb +105 -0
  86. data/test/scout/association/test_index.rb +70 -0
  87. data/test/scout/association/test_item.rb +21 -0
  88. data/test/scout/entity/test_format.rb +19 -0
  89. data/test/scout/entity/test_identifiers.rb +58 -0
  90. data/test/scout/entity/test_object.rb +0 -0
  91. data/test/scout/entity/test_property.rb +345 -0
  92. data/test/scout/{tsv/persist → persist/engine}/test_fix_width_table.rb +0 -1
  93. data/test/scout/persist/engine/test_packed_index.rb +99 -0
  94. data/test/scout/persist/engine/test_sharder.rb +31 -0
  95. data/test/scout/persist/engine/test_tkrzw.rb +0 -0
  96. data/test/scout/persist/engine/test_tokyocabinet.rb +17 -0
  97. data/test/scout/persist/test_tsv.rb +146 -0
  98. data/test/scout/{tsv/persist/test_adapter.rb → persist/tsv/adapter/test_base.rb} +3 -4
  99. data/test/scout/persist/tsv/adapter/test_fix_width_table.rb +46 -0
  100. data/test/scout/persist/tsv/adapter/test_packed_index.rb +37 -0
  101. data/test/scout/persist/tsv/adapter/test_serialize.rb +0 -0
  102. data/test/scout/persist/tsv/adapter/test_sharder.rb +290 -0
  103. data/test/scout/{tsv/persist → persist/tsv/adapter}/test_tkrzw.rb +3 -6
  104. data/test/scout/persist/tsv/adapter/test_tokyocabinet.rb +282 -0
  105. data/test/scout/persist/tsv/test_serialize.rb +12 -0
  106. data/test/scout/test_association.rb +51 -0
  107. data/test/scout/test_entity.rb +40 -0
  108. data/test/scout/test_tsv.rb +33 -4
  109. data/test/scout/test_work_queue.rb +3 -2
  110. data/test/scout/test_workflow.rb +16 -15
  111. data/test/scout/tsv/annotation/test_repo.rb +150 -0
  112. data/test/scout/tsv/change_id/test_translate.rb +178 -0
  113. data/test/scout/tsv/test_annotation.rb +52 -0
  114. data/test/scout/tsv/test_attach.rb +226 -1
  115. data/test/scout/tsv/test_change_id.rb +25 -0
  116. data/test/scout/tsv/test_csv.rb +50 -0
  117. data/test/scout/tsv/test_dumper.rb +38 -0
  118. data/test/scout/tsv/test_entity.rb +0 -0
  119. data/test/scout/tsv/test_index.rb +82 -0
  120. data/test/scout/tsv/test_open.rb +44 -0
  121. data/test/scout/tsv/test_parser.rb +70 -0
  122. data/test/scout/tsv/test_stream.rb +22 -0
  123. data/test/scout/tsv/test_transformer.rb +27 -3
  124. data/test/scout/tsv/test_traverse.rb +78 -0
  125. data/test/scout/tsv/util/test_process.rb +16 -0
  126. data/test/scout/tsv/util/test_reorder.rb +67 -0
  127. data/test/scout/tsv/util/test_sort.rb +28 -1
  128. data/test/scout/tsv/util/test_unzip.rb +32 -0
  129. data/test/scout/work_queue/test_socket.rb +4 -1
  130. data/test/scout/workflow/deployment/test_orchestrator.rb +17 -26
  131. data/test/scout/workflow/deployment/test_trace.rb +25 -0
  132. data/test/scout/workflow/step/test_archive.rb +28 -0
  133. data/test/scout/workflow/step/test_children.rb +25 -0
  134. data/test/scout/workflow/step/test_info.rb +16 -0
  135. data/test/scout/workflow/task/test_dependencies.rb +16 -16
  136. data/test/scout/workflow/task/test_inputs.rb +45 -1
  137. data/test/scout/workflow/test_definition.rb +52 -0
  138. data/test/scout/workflow/test_step.rb +57 -0
  139. data/test/scout/workflow/test_task.rb +26 -1
  140. data/test/scout/workflow/test_usage.rb +4 -4
  141. data/test/test_helper.rb +23 -1
  142. metadata +71 -14
  143. data/lib/scout/tsv/persist.rb +0 -27
  144. data/test/scout/tsv/persist/test_tokyocabinet.rb +0 -120
  145. data/test/scout/tsv/test_persist.rb +0 -45
@@ -1,5 +1,6 @@
1
1
  require 'scout/path'
2
2
  require 'scout/persist'
3
+ require 'scout/semaphore'
3
4
  require_relative 'step/info'
4
5
  require_relative 'step/status'
5
6
  require_relative 'step/load'
@@ -9,11 +10,13 @@ require_relative 'step/provenance'
9
10
  require_relative 'step/config'
10
11
  require_relative 'step/progress'
11
12
  require_relative 'step/inputs'
13
+ require_relative 'step/children'
14
+ require_relative 'step/archive'
12
15
 
13
16
  class Step
14
17
 
15
- attr_accessor :path, :inputs, :dependencies, :id, :task, :tee_copies, :non_default_inputs, :provided_inputs, :compute, :overriden_task, :overriden_workflow
16
- def initialize(path = nil, inputs = nil, dependencies = nil, id = nil, non_default_inputs = nil, provided_inputs = nil, compute = nil, &task)
18
+ attr_accessor :path, :inputs, :dependencies, :id, :task, :tee_copies, :non_default_inputs, :provided_inputs, :compute, :overriden_task, :overriden_workflow, :workflow, :exec_context, :overriden
19
+ def initialize(path = nil, inputs = nil, dependencies = nil, id = nil, non_default_inputs = nil, provided_inputs = nil, compute = nil, exec_context = nil, &task)
17
20
  @path = path
18
21
  @inputs = inputs
19
22
  @dependencies = dependencies
@@ -24,6 +27,7 @@ class Step
24
27
  @task = task
25
28
  @mutex = Mutex.new
26
29
  @tee_copies = 1
30
+ @exec_context = exec_context || self
27
31
  end
28
32
 
29
33
  def synchronize(&block)
@@ -44,10 +48,11 @@ class Step
44
48
 
45
49
  def dependencies
46
50
  @dependencies ||= begin
47
- if Open.exists?(info_file)
51
+ if info_file && Open.exists?(info_file) && info[:dependencies]
48
52
  info[:dependencies].collect do |path|
53
+ path = path.last if Array === path
49
54
  Step.load(path)
50
- end if info[:dependencies]
55
+ end
51
56
  else
52
57
  []
53
58
  end
@@ -56,7 +61,7 @@ class Step
56
61
 
57
62
  attr_accessor :type
58
63
  def type
59
- @type ||= @task.respond_to?(:type) ? @task.type : info[:type]
64
+ @type ||= (@task.respond_to?(:type) && @task.type) ? @task.type : info[:type]
60
65
  end
61
66
 
62
67
  def name
@@ -70,7 +75,9 @@ class Step
70
75
  def clean_name
71
76
  return @id if @id
72
77
  return info[:clean_name] if info.include? :clean_name
73
- return m[1] if m = name.match(/(.*?)(?:_[a-z0-9]{32})?(?:\..*)?/)
78
+ if m = name.match(/(.*?)(?:_[a-z0-9]{32})?(?:\..*)?/)
79
+ return m[1]
80
+ end
74
81
  return name.split(".").first
75
82
  end
76
83
 
@@ -82,10 +89,16 @@ class Step
82
89
 
83
90
  def workflow
84
91
  @workflow ||= @task.workflow if Task === @task
85
- @workflow ||= info[:workflow] if Open.exist?(info_file)
92
+ @workflow ||= info[:workflow] if info_file && Open.exist?(info_file)
86
93
  @workflow ||= path.split("/")[-3]
87
94
  end
88
95
 
96
+ def full_task_name
97
+ return nil if task_name.nil?
98
+ return task_name.to_s if workflow.nil?
99
+ [workflow, task_name] * "#"
100
+ end
101
+
89
102
  def exec
90
103
 
91
104
  if inputs
@@ -107,7 +120,7 @@ class Step
107
120
 
108
121
  @result = begin
109
122
  @in_exec = true
110
- self.instance_exec(*inputs, &task)
123
+ @exec_context.instance_exec(*inputs, &task)
111
124
  ensure
112
125
  @in_exec = false
113
126
  end
@@ -127,23 +140,37 @@ class Step
127
140
  def run(stream = false)
128
141
  return @result || self.load if done?
129
142
  prepare_dependencies
130
- run_dependencies
131
143
  begin
132
- @result = Persist.persist(name, type, :path => path, :tee_copies => tee_copies) do
133
- clear_info
144
+
145
+ case stream
146
+ when TrueClass, :stream
147
+ no_load = :stream
148
+ when :no_load
149
+ no_load = true
150
+ else
151
+ no_load = false
152
+ end
153
+
154
+ @result = Persist.persist(name, type, :path => path, :tee_copies => tee_copies, no_load: no_load) do
134
155
  input_names = (task.respond_to?(:inputs) && task.inputs) ? task.inputs.collect{|name,_| name} : []
135
- merge_info :status => :start, :start => Time.now,
156
+
157
+
158
+ reset_info :status => :setup, :issued => Time.now,
136
159
  :pid => Process.pid, :pid_hostname => Misc.hostname,
137
160
  :task_name => task_name, :workflow => workflow.to_s,
138
- :inputs => MetaExtension.purge(inputs), :input_names => input_names, :type => type,
139
- :dependencies => dependencies.collect{|d| d.path }
161
+ :inputs => Annotation.purge(inputs), :input_names => input_names, :type => type,
162
+ :dependencies => (dependencies || []) .collect{|d| d.path }
140
163
 
164
+ run_dependencies
165
+
166
+ set_info :start, Time.now
167
+ log :start
141
168
  @exec_result = exec
142
169
 
143
170
  if @exec_result.nil? && File.exist?(self.tmp_path) && ! File.exist?(self.path)
144
171
  Open.mv self.tmp_path, self.path
145
172
  else
146
- @exec_result = @exec_result.stream if @exec_result.respond_to?(:stream)
173
+ @exec_result = @exec_result.stream if @exec_result.respond_to?(:stream) && ! (TSV === @exec_result)
147
174
  end
148
175
 
149
176
  @exec_result
@@ -155,13 +182,25 @@ class Step
155
182
  @exec_result
156
183
  end
157
184
  end
185
+
186
+ if TrueClass === no_load
187
+ consume_all_streams if streaming?
188
+ @result = nil
189
+ elsif no_load && ! (IO === @result)
190
+ @result = nil
191
+ end
192
+
193
+ @result
158
194
  rescue Exception => e
159
- merge_info :status => :error, :exception => e, :end => Time.now
160
- abort_dependencies
161
- raise e
195
+ merge_info :status => :error, :exception => e, :end => Time.now, :backtrace => e.backtrace, :message => "#{e.class}: #{e.message}"
196
+ begin
197
+ abort_dependencies
198
+ ensure
199
+ raise e
200
+ end
162
201
  ensure
163
202
  if ! (error? || aborted?)
164
- if streaming?
203
+ if @result && streaming?
165
204
  ConcurrentStream.setup(@result) do
166
205
  merge_info :status => :done, :end => Time.now
167
206
  end
@@ -187,12 +226,22 @@ class Step
187
226
  end
188
227
  end
189
228
 
190
- def fork
191
- Process.fork do
192
- clear_info unless present?
193
- run(false)
229
+ def fork(noload = false, semaphore = nil)
230
+ pid = Process.fork do
231
+ Signal.trap(:TERM) do
232
+ raise Aborted, "Recieved TERM Signal on forked process #{Process.pid}"
233
+ end
234
+ reset_info status: :queue, pid: Process.pid unless present?
235
+ if semaphore
236
+ ScoutSemaphore.synchronize(semaphore) do
237
+ run(noload)
238
+ end
239
+ else
240
+ run(noload)
241
+ end
194
242
  join
195
243
  end
244
+ Process.detach pid
196
245
  grace
197
246
  self
198
247
  end
@@ -272,17 +321,23 @@ class Step
272
321
  while @result.nil? && (present? && ! (terminated? || done?))
273
322
  sleep 0.1
274
323
  end
324
+
325
+ Misc.wait_child info[:pid] if info[:pid]
326
+
275
327
  raise self.exception if self.exception
328
+
276
329
  raise "Error in job #{self.path}" if self.error? or self.aborted?
330
+
277
331
  self
278
332
  end
279
333
 
280
334
  def produce(with_fork: false)
335
+ clean if error? && recoverable_error?
281
336
  if with_fork
282
337
  self.fork
283
338
  self.join
284
339
  else
285
- run
340
+ run(:no_load)
286
341
  end
287
342
  self
288
343
  end
@@ -305,7 +360,7 @@ class Step
305
360
  end
306
361
 
307
362
  def short_path
308
- Scout.identify @path
363
+ Resource.identify @path
309
364
  end
310
365
 
311
366
  def digest_str
@@ -19,7 +19,7 @@ module Task
19
19
  step_inputs.each do |k,v|
20
20
  if Symbol === v
21
21
  input_dep = dependencies.select{|d| d.task_name == v }.first
22
- resolved_inputs[k] = input_dep || provided_inputs[v] || step_inputs[v] || k
22
+ resolved_inputs[k] = input_dep || provided_inputs[v] || step_inputs[v] || v
23
23
  else
24
24
  resolved_inputs[k] = v
25
25
  end
@@ -31,6 +31,9 @@ module Task
31
31
  compute_options << :produce if definition_options[:produce]
32
32
  compute_options << :stream if definition_options[:stream]
33
33
  compute[job.path] = compute_options if compute_options.any?
34
+
35
+ job.overriden = false if definition_options[:not_overriden]
36
+
34
37
  [job, step_inputs]
35
38
  end
36
39
 
@@ -40,7 +40,16 @@ module Task
40
40
  input_names << name
41
41
  provided = Hash === provided_inputs ? provided_inputs[name] : provided_inputs[i]
42
42
  provided = Task.format_input(provided, type, options || {})
43
- if ! provided.nil? && provided != value
43
+ if provided == value
44
+ same_as_default = true
45
+ elsif String === provided && Symbol === value && provided == value.to_s
46
+ same_as_default = true
47
+ elsif String === value && Symbol === provided && provided.to_s == value
48
+ same_as_default = true
49
+ else
50
+ same_as_default = false
51
+ end
52
+ if ! provided.nil? && ! same_as_default
44
53
  non_default_inputs << name.to_sym
45
54
  input_array << provided
46
55
  elsif options && options[:jobname]
@@ -61,7 +70,7 @@ module Task
61
70
  [input_array, non_default_inputs, digest_str]
62
71
  end
63
72
 
64
- def save_file_input(orig_file, directory)
73
+ def self.save_file_input(orig_file, directory)
65
74
  orig_file = orig_file.path if Step === orig_file
66
75
  basename = File.basename(orig_file)
67
76
  digest = Misc.digest(orig_file)
@@ -76,38 +85,65 @@ module Task
76
85
  relative_file
77
86
  end
78
87
 
88
+ def self.save_input(directory, name, type, value)
89
+ input_file = File.join(directory, name.to_s)
90
+
91
+ if Path.is_filename?(value)
92
+ if type == :path
93
+ Open.write(input_file + ".as_path", value)
94
+ else
95
+ relative_file = save_file_input(value, directory)
96
+ Open.write(input_file + ".as_file", relative_file)
97
+ end
98
+ elsif Step === value
99
+ Open.write(input_file + ".as_step", value.short_path)
100
+ elsif type == :file
101
+ relative_file = save_file_input(value, directory)
102
+ Persist.save(relative_file, input_file, :file)
103
+ elsif type == :file_array
104
+ new_files = value.collect do |orig_file|
105
+ save_file_input(orig_file, directory)
106
+ end
107
+ Persist.save(new_files, input_file, type)
108
+ elsif Open.is_stream?(value)
109
+ Open.sensible_write(input_file, value)
110
+ elsif Open.has_stream?(value)
111
+ Open.sensible_write(input_file, value.stream)
112
+ else
113
+ Persist.save(value, input_file, type)
114
+ end
115
+ end
116
+
79
117
  def save_inputs(directory, provided_inputs = {})
80
- #input_array, non_default_inputs = assign_inputs(provided_inputs)
81
118
  self.recursive_inputs.each_with_index do |p,i|
82
119
  name, type, desc, value, options = p
83
120
  next unless provided_inputs.include?(name)
84
121
  value = provided_inputs[name]
85
- input_file = File.join(directory, name.to_s)
86
-
87
- if Path.is_filename?(value)
88
- if type == :path
89
- Open.write(input_file + ".as_path", value)
90
- else
91
- relative_file = save_file_input(value, directory)
92
- Open.write(input_file + ".as_file", relative_file)
93
- end
94
- elsif Step === value
95
- Open.write(input_file + ".as_step", value.short_path)
96
- elsif type == :file
97
- relative_file = save_file_input(value, directory)
98
- Persist.save(relative_file, input_file, :file)
99
- elsif type == :file_array
100
- new_files = value.collect do |orig_file|
101
- save_file_input(orig_file, directory)
102
- end
103
- Persist.save(new_files, input_file, type)
104
- elsif Open.is_stream?(value)
105
- Persist.save(value, input_file, type)
106
- elsif Open.has_stream?(value)
107
- Persist.save(value.stream, input_file, type)
122
+
123
+ Task.save_input(directory, name, type, value)
124
+ end
125
+ end
126
+
127
+
128
+ def self.load_input_from_file(filename, type, options = nil)
129
+ if Open.exists?(filename) || filename = Dir.glob(File.join(filename + ".*")).first
130
+ if filename.end_with?('.as_file')
131
+ value = Open.read(filename).strip
132
+ value.sub!(/^\./, File.dirname(filename)) if value.start_with?("./")
133
+ value
134
+ elsif filename.end_with?('.as_step')
135
+ value = Open.read(filename).strip
136
+ Step.load value
137
+ elsif filename.end_with?('.as_path')
138
+ value = Open.read(filename).strip
139
+ Path.setup value
140
+ elsif (options && (options[:noload] || options[:stream] || options[:nofile]))
141
+ filename
108
142
  else
109
- Persist.save(value, input_file, type)
143
+ Persist.load(filename, type)
110
144
  end
145
+ else
146
+ return nil
111
147
  end
112
148
  end
113
149
 
@@ -116,21 +152,35 @@ module Task
116
152
  self.recursive_inputs.each do |p|
117
153
  name, type, desc, value, options = p
118
154
  filename = File.join(directory, name.to_s)
119
- if Open.exists?(filename) || filename = Dir.glob(File.join(filename + ".*")).first
120
- if filename.end_with?('.as_file')
121
- value = Open.read(filename).strip
122
- value.sub!(/^\./, File.dirname(filename)) if value.start_with?("./")
123
- inputs[name] = value
124
- elsif filename.end_with?('.as_step')
125
- value = Open.read(filename).strip
126
- inputs[name] = Step.load value
127
- elsif (options && (options[:noload] || options[:stream] || options[:nofile]))
128
- inputs[name] = filename
129
- else
130
- inputs[name] = Persist.load(filename, type)
131
- end
132
- end
155
+ value = Task.load_input_from_file(filename, type, options)
156
+ inputs[name] = value unless value.nil?
157
+ end
158
+
159
+ Dir.glob(File.join(directory, "*#*")).each do |file|
160
+ override_dep, _, extension = File.basename(file).partition(".")
161
+
162
+ inputs[override_dep] = Task.load_input_from_file(file, :file)
133
163
  end
164
+
134
165
  inputs
135
166
  end
167
+
168
+ def recursive_inputs(overriden = [])
169
+ return inputs.dup if deps.nil?
170
+ deps.inject(inputs.dup) do |acc,dep|
171
+ workflow, task, options = dep
172
+ next acc if workflow.nil? || task.nil?
173
+ next acc if overriden.include?([workflow.name, task.to_s] * "#")
174
+ overriden.concat options.keys.select{|k| k.to_s.include?("#") } if options
175
+
176
+ workflow.tasks[task].recursive_inputs(overriden).dup.each do |info|
177
+ name, _ = info
178
+ next if options.include?(name.to_sym) || options.include?(name.to_s)
179
+ acc << info
180
+ end
181
+
182
+ acc
183
+ end
184
+ end
185
+
136
186
  end
@@ -1,12 +1,12 @@
1
- require 'scout/meta_extension'
1
+ require 'scout/annotation'
2
2
  require 'scout/named_array'
3
3
  require_relative 'step'
4
4
  require_relative 'task/inputs'
5
5
  require_relative 'task/dependencies'
6
6
 
7
7
  module Task
8
- extend MetaExtension
9
- extension_attr :name, :type, :inputs, :deps, :directory, :description, :returns, :extension, :workflow
8
+ extend Annotation
9
+ annotation :name, :type, :inputs, :deps, :directory, :description, :returns, :extension, :workflow
10
10
 
11
11
  DEFAULT_NAME = "Default"
12
12
 
@@ -22,15 +22,6 @@ module Task
22
22
  @inputs ||= []
23
23
  end
24
24
 
25
- def recursive_inputs
26
- return inputs if deps.nil?
27
- deps.inject(inputs) do |acc,dep|
28
- workflow, task = dep
29
- next acc if workflow.nil? || task.nil?
30
- acc += workflow.tasks[task].recursive_inputs
31
- end
32
- end
33
-
34
25
  def directory
35
26
  @directory ||= Task.default_directory
36
27
  end
@@ -39,75 +30,81 @@ module Task
39
30
  binding.instance_exec(*inputs, &self)
40
31
  end
41
32
 
42
- def job(id = DEFAULT_NAME, provided_inputs = nil )
43
- provided_inputs, id = id, DEFAULT_NAME if (provided_inputs.nil? || provided_inputs.empty?) && (Hash === id || Array === id)
44
- provided_inputs = {} if provided_inputs.nil?
45
- IndiferentHash.setup(provided_inputs)
46
- id = DEFAULT_NAME if id.nil?
33
+ def job(id = nil, provided_inputs = nil)
34
+ Persist.memory("Task job", other_options: {task: self, id: id, provided_inputs: provided_inputs}) do
35
+ provided_inputs, id = id, nil if (provided_inputs.nil? || provided_inputs.empty?) && (Hash === id || Array === id)
36
+ provided_inputs = {} if provided_inputs.nil?
37
+ IndiferentHash.setup(provided_inputs)
47
38
 
39
+ if id.nil?
40
+ inputs.each do |name,type,desc,default,input_options|
41
+ next unless input_options && input_options[:jobname]
42
+ id = provided_inputs[name] || default
43
+ end
44
+ id = DEFAULT_NAME if id.nil?
45
+ end
48
46
 
49
- missing_inputs = []
50
- self.inputs.each do |input,type,desc,val,options|
51
- next unless options && options[:required]
52
- missing_inputs << input unless provided_inputs.include?(input)
53
- end if self.inputs
47
+ missing_inputs = []
48
+ self.inputs.each do |input,type,desc,val,options|
49
+ next unless options && options[:required]
50
+ missing_inputs << input unless provided_inputs.include?(input)
51
+ end if self.inputs
54
52
 
55
- if missing_inputs.length == 1
56
- raise ParameterException, "Input '#{missing_inputs.first}' is required but was not provided or is nil"
57
- end
53
+ if missing_inputs.length == 1
54
+ raise ParameterException, "Input '#{missing_inputs.first}' is required but was not provided or is nil"
55
+ end
58
56
 
59
- if missing_inputs.length > 1
60
- raise ParameterException, "Inputs #{Misc.humanize_list(missing_inputs)} are required but were not provided or are nil"
61
- end
57
+ if missing_inputs.length > 1
58
+ raise ParameterException, "Inputs #{Misc.humanize_list(missing_inputs)} are required but were not provided or are nil"
59
+ end
62
60
 
63
- provided_inputs = load_inputs(provided_inputs[:load_inputs]) if Hash === provided_inputs && provided_inputs[:load_inputs]
61
+ provided_inputs = load_inputs(provided_inputs.delete(:load_inputs)).merge(provided_inputs) if Hash === provided_inputs && provided_inputs[:load_inputs]
64
62
 
65
- inputs, non_default_inputs, input_digest_str = process_inputs provided_inputs, id
63
+ job_inputs, non_default_inputs, input_digest_str = process_inputs provided_inputs, id
66
64
 
67
- compute = {}
68
- dependencies = dependencies(id, provided_inputs, non_default_inputs, compute)
65
+ compute = {}
66
+ dependencies = dependencies(id, provided_inputs, non_default_inputs, compute)
69
67
 
70
- #non_default_inputs.concat provided_inputs.keys.select{|k| String === k && k.include?("#") } if Hash === provided_inputs
68
+ #non_default_inputs.concat provided_inputs.keys.select{|k| String === k && k.include?("#") } if Hash === provided_inputs
71
69
 
72
- non_default_inputs.uniq!
70
+ non_default_inputs.uniq!
73
71
 
74
- if non_default_inputs.any?
75
- hash = Misc.digest(:inputs => input_digest_str, :dependencies => dependencies)
76
- name = [id, hash] * "_"
77
- else
78
- name = id
79
- end
72
+ if non_default_inputs.any?
73
+ hash = Misc.digest(:inputs => input_digest_str, :dependencies => dependencies)
74
+ name = [id, hash] * "_"
75
+ else
76
+ name = id
77
+ end
80
78
 
81
- extension = self.extension
82
- if extension == :dep_task
83
- extension = nil
84
- if dependencies.any?
85
- dep_basename = File.basename(dependencies.last.path)
86
- if dep_basename.include? "."
87
- parts = dep_basename.split(".")
88
- extension = [parts.pop]
89
- while parts.last.length <= 4
90
- extension << parts.pop
79
+ extension = self.extension
80
+ if extension == :dep_task
81
+ extension = nil
82
+ if dependencies.any?
83
+ dep_basename = File.basename(dependencies.last.path)
84
+ if dep_basename.include? "."
85
+ parts = dep_basename.split(".")
86
+ extension = [parts.pop]
87
+ while parts.last.length <= 4
88
+ extension << parts.pop
89
+ end
90
+ extension = extension.reverse * "."
91
91
  end
92
- extension = extension.reverse * "."
93
92
  end
94
93
  end
95
- end
96
94
 
97
95
 
98
- path = directory[name]
96
+ path = directory[name]
99
97
 
100
- path = path.set_extension(extension) if extension
98
+ path = path.set_extension(extension) if extension
101
99
 
102
- Persist.memory(path) do
103
100
  if hash
104
101
  Log.debug "ID #{self.name} #{id} - #{hash}: #{Log.fingerprint(:input_digest => input_digest_str, :non_default_inputs => non_default_inputs, :dependencies => dependencies)}"
105
102
  else
106
103
  Log.debug "ID #{self.name} #{id} - Clean"
107
104
  end
108
- NamedArray.setup(inputs, @inputs.collect{|i| i[0] }) if @inputs
105
+ NamedArray.setup(job_inputs, @inputs.collect{|i| i[0] }) if @inputs
109
106
  step_provided_inputs = Hash === provided_inputs ? provided_inputs.slice(*non_default_inputs) : provided_inputs
110
- Step.new path.find, inputs, dependencies, id, non_default_inputs, step_provided_inputs, compute, &self
107
+ Step.new path.find, job_inputs, dependencies, id, non_default_inputs, step_provided_inputs, compute, &self
111
108
  end
112
109
  end
113
110
 
@@ -114,6 +114,7 @@ module Task
114
114
  def get_SOPT
115
115
  sopt_option_string = self.SOPT_str
116
116
  job_options = SOPT.get sopt_option_string
117
+
117
118
  recursive_inputs.uniq.each do |name,type|
118
119
  next unless type.to_s.include?('array')
119
120
  if job_options.include?(name) && (! Open.exist?(job_options[name]) || type.to_s.include?('file') || type.to_s.include?('path'))
@@ -285,7 +286,6 @@ module Workflow
285
286
  task = self.tasks[task_name]
286
287
  end
287
288
 
288
- #dependencies = self.rec_dependencies(task_name).collect{|dep_name| Array === dep_name ? dep_name.first.tasks[dep_name[1].to_sym] : self.tasks[dep_name.to_sym]}
289
289
  str.puts task.usage(self, self.recursive_deps(task_name))
290
290
 
291
291
  dep_tree = {[self, task_name] => dep_tree(task_name)}
@@ -8,6 +8,10 @@ module Workflow
8
8
  mod
9
9
  end
10
10
 
11
+ def self.installed_workflows
12
+ Path.setup("workflows").glob_all("*").collect{|f| File.basename(f) }.uniq
13
+ end
14
+
11
15
  def find_in_dependencies(name, dependencies)
12
16
  name = name.to_sym
13
17
  dependencies.select{|dep| dep.task_name.to_sym == name }