Class: Tapsoob::Chunksize
- Inherits:
-
Object
- Object
- Tapsoob::Chunksize
- Defined in:
- lib/tapsoob/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.
8 9 10 11 12 |
# File 'lib/tapsoob/chunksize.rb', line 8 def initialize(chunksize) @chunksize = chunksize @idle_secs = 0.0 @retries = 0 end |
Instance Attribute Details
#chunksize ⇒ Object (readonly)
Returns the value of attribute chunksize.
6 7 8 |
# File 'lib/tapsoob/chunksize.rb', line 6 def chunksize @chunksize end |
#end_time ⇒ Object
Returns the value of attribute end_time.
5 6 7 |
# File 'lib/tapsoob/chunksize.rb', line 5 def end_time @end_time end |
#idle_secs ⇒ Object
Returns the value of attribute idle_secs.
5 6 7 |
# File 'lib/tapsoob/chunksize.rb', line 5 def idle_secs @idle_secs end |
#retries ⇒ Object
Returns the value of attribute retries.
5 6 7 |
# File 'lib/tapsoob/chunksize.rb', line 5 def retries @retries end |
#start_time ⇒ Object
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/tapsoob/chunksize.rb', line 5 def start_time @start_time end |
#time_in_db ⇒ Object
Returns the value of attribute time_in_db.
5 6 7 |
# File 'lib/tapsoob/chunksize.rb', line 5 def time_in_db @time_in_db end |
Instance Method Details
#calc_new_chunksize ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tapsoob/chunksize.rb', line 38 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
22 23 24 |
# File 'lib/tapsoob/chunksize.rb', line 22 def diff end_time - start_time - time_in_db - idle_secs end |
#reset_chunksize ⇒ Object
18 19 20 |
# File 'lib/tapsoob/chunksize.rb', line 18 def reset_chunksize @chunksize = (retries <= 1) ? 10 : 1 end |
#time_delta ⇒ Object
31 32 33 34 35 36 |
# File 'lib/tapsoob/chunksize.rb', line 31 def time_delta t1 = Time.now yield if block_given? t2 = Time.now t2 - t1 end |
#to_i ⇒ Object
14 15 16 |
# File 'lib/tapsoob/chunksize.rb', line 14 def to_i chunksize end |