Class: OpenTox::SubTask
- Inherits:
-
Object
- Object
- OpenTox::SubTask
- Defined in:
- lib/task.rb
Overview
Convenience class to split a (sub)task into subtasks
example: a crossvalidation is split into creating datasets and performing the validations creating the dataset is 1/3 of the work, perform the validations is 2/3: Task.as_task do |task|
create_datasets( SubTask.new(task, 0, 33) )
perfom_validations( SubTask.new(task, 33, 100) )
end inside the create_datasets / perform_validations you can use subtask.progress(<val>) with vals from 0-100
note that you can split a subtask into further subtasks
Class Method Summary collapse
-
.create(task, min, max) ⇒ Object
convenience method to handle null tasks.
Instance Method Summary collapse
-
#initialize(task, min, max) ⇒ SubTask
constructor
A new instance of SubTask.
- #progress(pct) ⇒ Object
- #running? ⇒ Boolean
- #waiting_for(task_uri) ⇒ Object
Constructor Details
#initialize(task, min, max) ⇒ SubTask
Returns a new instance of SubTask.
325 326 327 328 329 330 331 332 333 |
# File 'lib/task.rb', line 325 def initialize(task, min, max) raise "not a task or subtask" if task!=nil and !(task.is_a?(Task) or task.is_a?(SubTask)) raise "invalid max ("+max.to_s+"), min ("+min.to_s+") params" unless min.is_a?(Numeric) and max.is_a?(Numeric) and min >= 0 and max <= 100 and max > min @task = task @min = min @max = max @delta = max - min end |
Class Method Details
Instance Method Details
#progress(pct) ⇒ Object
348 349 350 351 352 |
# File 'lib/task.rb', line 348 def progress(pct) raise "no numeric >= 0 and <= 100 : '"+pct.to_s+"'" unless pct.is_a?(Numeric) and pct>=0 and pct<=100 #puts "subtask := "+pct.to_s+" -> task := "+(@min + @delta * pct.to_f * 0.01).to_s @task.progress( @min + @delta * pct.to_f * 0.01 ) end |
#running? ⇒ Boolean
354 355 356 |
# File 'lib/task.rb', line 354 def running?() @task.running? end |
#waiting_for(task_uri) ⇒ Object
344 345 346 |
# File 'lib/task.rb', line 344 def waiting_for(task_uri) @task.waiting_for(task_uri) end |