Class: Lhm::ChunkFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/lhm/chunk_finder.rb

Constant Summary collapse

LOG_PREFIX =
"Chunker"

Instance Method Summary collapse

Constructor Details

#initialize(migration, connection = nil, options = {}) ⇒ ChunkFinder

Returns a new instance of ChunkFinder.



5
6
7
8
9
10
11
12
# File 'lib/lhm/chunk_finder.rb', line 5

def initialize(migration, connection = nil, options = {})
  @migration = migration
  @connection = connection
  @start = options[:start] || select_start_from_db
  @limit = options[:limit] || select_limit_from_db
  @throttler = options[:throttler]
  @processed_rows = 0
end

Instance Method Details

#each_chunkObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/lhm/chunk_finder.rb', line 24

def each_chunk
  next_id = @start
  @processed_rows = 0
  while next_id <= @limit
    top = upper_id(next_id)
    @processed_rows += @throttler.stride
    yield ChunkInsert.new(@migration, @connection, next_id, top)
    next_id = top + 1
  end
end

#max_rowsObject



35
36
37
# File 'lib/lhm/chunk_finder.rb', line 35

def max_rows
  @limit - @start + 1
end

#processed_rowsObject



39
40
41
# File 'lib/lhm/chunk_finder.rb', line 39

def processed_rows
  @processed_rows
end

#table_empty?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/lhm/chunk_finder.rb', line 14

def table_empty?
  start.nil? && limit.nil?
end

#validateObject



18
19
20
21
22
# File 'lib/lhm/chunk_finder.rb', line 18

def validate
  if start > limit
    raise ArgumentError, "impossible chunk options (limit (#{limit.inspect} must be greater than start (#{start.inspect})"
  end
end