Class: Taps::Chunksize
- Inherits:
-
Object
- Object
- Taps::Chunksize
- Defined in:
- lib/taps/chunksize.rb
Instance Attribute Summary collapse
-
#chunksize ⇒ Object
readonly
Returns the value of attribute chunksize.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#idle_secs ⇒ Object
Returns the value of attribute idle_secs.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#time_in_db ⇒ Object
Returns the value of attribute time_in_db.
Instance Method Summary collapse
- #calc_new_chunksize ⇒ Object
- #diff ⇒ Object
-
#initialize(chunksize) ⇒ Chunksize
constructor
A new instance of Chunksize.
- #reset_chunksize ⇒ Object
- #time_delta ⇒ Object
- #to_i ⇒ Object
Constructor Details
#initialize(chunksize) ⇒ Chunksize
Returns a new instance of Chunksize.
7 8 9 10 11 |
# File 'lib/taps/chunksize.rb', line 7 def initialize(chunksize) @chunksize = chunksize @idle_secs = 0.0 @retries = 0 end |
Instance Attribute Details
#chunksize ⇒ Object (readonly)
Returns the value of attribute chunksize.
5 6 7 |
# File 'lib/taps/chunksize.rb', line 5 def chunksize @chunksize end |
#end_time ⇒ Object
Returns the value of attribute end_time.
4 5 6 |
# File 'lib/taps/chunksize.rb', line 4 def end_time @end_time end |
#idle_secs ⇒ Object
Returns the value of attribute idle_secs.
4 5 6 |
# File 'lib/taps/chunksize.rb', line 4 def idle_secs @idle_secs end |
#retries ⇒ Object
Returns the value of attribute retries.
4 5 6 |
# File 'lib/taps/chunksize.rb', line 4 def retries @retries end |
#start_time ⇒ Object
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/taps/chunksize.rb', line 4 def start_time @start_time end |
#time_in_db ⇒ Object
Returns the value of attribute time_in_db.
4 5 6 |
# File 'lib/taps/chunksize.rb', line 4 def time_in_db @time_in_db end |
Instance Method Details
#calc_new_chunksize ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/taps/chunksize.rb', line 37 def calc_new_chunksize new_chunksize = if retries > 0 chunksize elsif diff > 3.0 (chunksize / 3).ceil elsif diff > 1.1 chunksize - 100 elsif diff < 0.8 chunksize * 2 else chunksize + 100 end new_chunksize = 1 if new_chunksize < 1 new_chunksize end |
#diff ⇒ Object
21 22 23 |
# File 'lib/taps/chunksize.rb', line 21 def diff end_time - start_time - time_in_db - idle_secs end |
#reset_chunksize ⇒ Object
17 18 19 |
# File 'lib/taps/chunksize.rb', line 17 def reset_chunksize @chunksize = (retries <= 1) ? 10 : 1 end |
#time_delta ⇒ Object
30 31 32 33 34 35 |
# File 'lib/taps/chunksize.rb', line 30 def time_delta t1 = Time.now yield if block_given? t2 = Time.now t2 - t1 end |
#to_i ⇒ Object
13 14 15 |
# File 'lib/taps/chunksize.rb', line 13 def to_i chunksize end |