Class: OpenTox::FakeSubTask
- Inherits:
-
Object
- Object
- OpenTox::FakeSubTask
- 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
-
.create(task, runtime) ⇒ Object
convenience method to handle null tasks.
Instance Method Summary collapse
- #finished ⇒ Object
-
#initialize(task, runtime) ⇒ FakeSubTask
constructor
A new instance of FakeSubTask.
Constructor Details
#initialize(task, runtime) ⇒ FakeSubTask
Returns a new instance of FakeSubTask.
382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/task.rb', line 382 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
395 396 397 398 399 400 401 |
# File 'lib/task.rb', line 395 def self.create(task, runtime) if task FakeSubTask.new(task, runtime) else nil end end |
Instance Method Details
#finished ⇒ Object
403 404 405 406 |
# File 'lib/task.rb', line 403 def finished @thread.exit @task.progress(100) if @task.running? end |