Class: Ke::IndeterminateTask
- Inherits:
-
Object
- Object
- Ke::IndeterminateTask
- Defined in:
- lib/ke/indeterminate_task.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#complete_time ⇒ Object
readonly
Returns the value of attribute complete_time.
-
#tick_count ⇒ Object
readonly
Returns the value of attribute tick_count.
Instance Method Summary collapse
- #complete ⇒ Object
- #duration_per_tick ⇒ Object
- #elapsed_duration ⇒ Object
-
#initialize(opts = {}) ⇒ IndeterminateTask
constructor
A new instance of IndeterminateTask.
- #start ⇒ Object
- #start_time ⇒ Object
- #tick ⇒ Object
- #total_duration ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ IndeterminateTask
Returns a new instance of IndeterminateTask.
5 6 7 8 9 10 |
# File 'lib/ke/indeterminate_task.rb', line 5 def initialize(opts = {}) @tick_count = 0 @duration_per_tick = 0 @duration_per_tick_history = CappedSample.new(100) @mutex = Mutex.new end |
Instance Attribute Details
#complete_time ⇒ Object (readonly)
Returns the value of attribute complete_time.
3 4 5 |
# File 'lib/ke/indeterminate_task.rb', line 3 def complete_time @complete_time end |
#tick_count ⇒ Object (readonly)
Returns the value of attribute tick_count.
3 4 5 |
# File 'lib/ke/indeterminate_task.rb', line 3 def tick_count @tick_count end |
Instance Method Details
#complete ⇒ Object
42 43 44 |
# File 'lib/ke/indeterminate_task.rb', line 42 def complete @complete_time = Time.now end |
#duration_per_tick ⇒ Object
28 29 30 |
# File 'lib/ke/indeterminate_task.rb', line 28 def duration_per_tick @duration_per_tick_history.mean end |
#elapsed_duration ⇒ Object
16 17 18 |
# File 'lib/ke/indeterminate_task.rb', line 16 def elapsed_duration Time.now - @start_time end |
#start ⇒ Object
24 25 26 |
# File 'lib/ke/indeterminate_task.rb', line 24 def start @start_time = Time.now end |
#start_time ⇒ Object
12 13 14 |
# File 'lib/ke/indeterminate_task.rb', line 12 def start_time @start_time end |
#tick ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/ke/indeterminate_task.rb', line 32 def tick @mutex.synchronize do this_tick_time = Time.now duration_this_tick = this_tick_time - (@last_tick_time || start_time) @duration_per_tick_history << duration_this_tick @last_tick_time = this_tick_time @tick_count += 1 end end |
#total_duration ⇒ Object
20 21 22 |
# File 'lib/ke/indeterminate_task.rb', line 20 def total_duration @complete_time - @start_time end |