Sha256: 6c6a08c9f0c5826cd7b80231c86ef178cff8f1ebe0ff88af63a4b50f233cf866

Contents?: true

Size: 926 Bytes

Versions: 21

Compression:

Stored size: 926 Bytes

Contents

require 'taps/errors'

class Taps::Chunksize
  attr_accessor :idle_secs, :time_in_db, :start_time, :end_time, :retries
  attr_reader :chunksize

  def initialize(chunksize)
    @chunksize = chunksize
    @idle_secs = 0.0
    @retries = 0
  end

  def to_i
    chunksize
  end

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

  def diff
    end_time - start_time - time_in_db - idle_secs
  end

  def time_in_db=(t)
    @time_in_db = t
    @time_in_db = @time_in_db.to_f rescue 0.0
  end

  def time_delta
    t1 = Time.now
    yield if block_given?
    t2 = Time.now
    t2 - t1
  end

  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
end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
taps2-0.5.5 lib/taps/chunksize.rb
taps2-0.5.4 lib/taps/chunksize.rb
taps2-0.5.3 lib/taps/chunksize.rb
taps2-0.5.2 lib/taps/chunksize.rb
taps2-0.5.1 lib/taps/chunksize.rb
tinroof-taps-0.3.24 lib/taps/chunksize.rb
tapsicle-0.4.1 lib/taps/chunksize.rb
taps-taps-0.3.24 lib/taps/chunksize.rb
taps-0.3.24 lib/taps/chunksize.rb
taps-0.3.23 lib/taps/chunksize.rb
taps-0.3.23.pre1 lib/taps/chunksize.rb
taps-0.3.22.pre2 lib/taps/chunksize.rb
taps-0.3.22.pre1 lib/taps/chunksize.rb
taps-0.3.21 lib/taps/chunksize.rb
taps-0.3.20 lib/taps/chunksize.rb
taps-0.3.20.pre2 lib/taps/chunksize.rb
taps-0.3.20.pre1 lib/taps/chunksize.rb
taps-0.3.19 lib/taps/chunksize.rb
taps-0.3.19.pre1 lib/taps/chunksize.rb
taps-0.3.18 lib/taps/chunksize.rb