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 11 |
# 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 @last_tick_time = nil 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
43 44 45 |
# File 'lib/ke/indeterminate_task.rb', line 43 def complete @complete_time = Time.now end |
#duration_per_tick ⇒ Object
29 30 31 |
# File 'lib/ke/indeterminate_task.rb', line 29 def duration_per_tick @duration_per_tick_history.mean_iqr end |
#elapsed_duration ⇒ Object
17 18 19 |
# File 'lib/ke/indeterminate_task.rb', line 17 def elapsed_duration Time.now - @start_time end |
#start ⇒ Object
25 26 27 |
# File 'lib/ke/indeterminate_task.rb', line 25 def start @start_time = Time.now end |
#start_time ⇒ Object
13 14 15 |
# File 'lib/ke/indeterminate_task.rb', line 13 def start_time @start_time end |
#tick ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/ke/indeterminate_task.rb', line 33 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
21 22 23 |
# File 'lib/ke/indeterminate_task.rb', line 21 def total_duration @complete_time - @start_time end |