Class: OpenTox::FakeSubTask

Inherits:
Object
  • Object
show all
Defined in:
lib/task.rb

Overview

The David Gallagher feature: a fake sub task to keep the progress bar movin for external jobs note: param could be a subtask

usage (for a call that is normally finished in under 60 seconds):

fsk = FakeSubTask.new(task, 60)
external_lib_call.start
external_lib_call.wait_until_finished
fsk.finished

what happens: the FakeSubTask updates the task.progress each second until runtime is up or the finished mehtod is called

example if the param runtime is too low:

25% .. 50% .. 75% .. 100% .. 100% .. 100% .. 100% .. 100%

example if the param runtime is too high:

5% .. 10% .. 15% ..  20% ..  25% ..  30% ..  35% .. 100%

the latter example is better (keep the bar movin!) -> better make a conservative runtime estimate

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, runtime) ⇒ FakeSubTask

Returns a new instance of FakeSubTask.



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/task.rb', line 369

def initialize(task, runtime)
  @task = task
  @thread = Thread.new do
    timeleft = runtime
    while (timeleft > 0 and @task.running?)
      sleep 1
      timeleft -= 1
      @task.progress( (runtime - timeleft) / runtime.to_f * 100 )
    end
  end
end

Class Method Details

.create(task, runtime) ⇒ Object

convenience method to handle null tasks



382
383
384
385
386
387
388
# File 'lib/task.rb', line 382

def self.create(task, runtime)
  if task
    FakeSubTask.new(task, runtime)
  else
    nil
  end
end

Instance Method Details

#finishedObject



390
391
392
393
# File 'lib/task.rb', line 390

def finished
  @thread.exit
  @task.progress(100) if @task.running?
end