Skip to content

Commit

Permalink
Add ActiveRecordBatchProcessor (no specs)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexParamonov committed Oct 19, 2016
1 parent 28c03df commit bde5fa2
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/processor/data/active_record_batch_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require_relative "null_processor"

module Processor
module Data
class ActiveRecordBatchProcessor < NullProcessor
attr_reader :source

def initialize(source:, presenter: -> { Hash.new }, output:, batch_size: 1000)
@source = source
@presenter = presenter
@output = output
@batch_size = batch_size
end

def records
source.find_each(batch_size: batch_size)
end

def process(record)
output.write presenter.call(record)
"OK"
end

def record_id(record)
record.id
end

def finalize
output.close
end

def total_records
@total_records ||= source.count
end

private
attr_reader :presenter, :output, :batch_size
end
end
end

0 comments on commit bde5fa2

Please sign in to comment.