Class: Processor::Data::BatchProcessor
Instance Method Summary
collapse
#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_batch ⇒ Object
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
|
#query ⇒ Object
31
32
33
|
# File 'lib/processor/data/batch_processor.rb', line 31
def query
raise NotImplementedError
end
|
#records ⇒ Object
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_records ⇒ Object
27
28
29
|
# File 'lib/processor/data/batch_processor.rb', line 27
def total_records
@total_records ||= query.count
end
|