Sha256: b38fff61a3293152f8053684839ae11934b8e10b98f08826beba7c68087529a8
Contents?: true
Size: 1.14 KB
Versions: 11
Compression:
Stored size: 1.14 KB
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 = begin @time_in_db.to_f rescue 0.0 end 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
11 entries across 11 versions & 1 rubygems