Class: Taps::Chunksize

Inherits:
Object
  • Object
show all
Defined in:
lib/taps/chunksize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#chunksizeObject (readonly)

Returns the value of attribute chunksize.



5
6
7
# File 'lib/taps/chunksize.rb', line 5

def chunksize
  @chunksize
end

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/taps/chunksize.rb', line 4

def end_time
  @end_time
end

#idle_secsObject

Returns the value of attribute idle_secs.



4
5
6
# File 'lib/taps/chunksize.rb', line 4

def idle_secs
  @idle_secs
end

#retriesObject

Returns the value of attribute retries.



4
5
6
# File 'lib/taps/chunksize.rb', line 4

def retries
  @retries
end

#start_timeObject

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_dbObject

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_chunksizeObject



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

#diffObject



21
22
23
# File 'lib/taps/chunksize.rb', line 21

def diff
  end_time - start_time - time_in_db - idle_secs
end

#reset_chunksizeObject



17
18
19
# File 'lib/taps/chunksize.rb', line 17

def reset_chunksize
  @chunksize = (retries <= 1) ? 10 : 1
end

#time_deltaObject



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_iObject



13
14
15
# File 'lib/taps/chunksize.rb', line 13

def to_i
  chunksize
end