Class: Processor::Data::BatchProcessor

Inherits:
NullProcessor show all
Defined in:
lib/processor/data/batch_processor.rb

Direct Known Subclasses

SolrPagesProcessor, SolrProcessor

Instance Method Summary collapse

Methods inherited from NullProcessor

#name, #process

Constructor Details

#initialize(batch_size = 10) ⇒ BatchProcessor

Returns a new instance of BatchProcessor.



6
7
8
# File 'lib/processor/data/batch_processor.rb', line 6

def initialize(batch_size = 10)
  @batch_size = batch_size
end

Instance Method Details

#fetch_batchObject



22
23
24
25
# File 'lib/processor/data/batch_processor.rb', line 22

def fetch_batch
  @fetcher ||= query.each_slice(batch_size)
  @fetcher.next
end

#queryObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/processor/data/batch_processor.rb', line 31

def query
  raise NotImplementedError
end

#recordsObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/processor/data/batch_processor.rb', line 10

def records
  Enumerator.new do |result|
    loop do
      batch = fetch_batch
      break if batch.count < 1
      batch.each do |record|
        result << record
      end
    end
  end
end

#total_recordsObject



27
28
29
# File 'lib/processor/data/batch_processor.rb', line 27

def total_records
  @total_records ||= query.count
end