I need to import a large CSV file, broken down to small chunks that will be imported every X hours.
I made the following rake task
task :import_reviews => :environment do
require 'csv'
CSV.foreach('reviews.csv', :headers => true) do |row|
Review.create(row.to_hash)
end
end
Using heroku scheduler I could let this task run every day, but I want to break it up in several chunks, for example 100 records every day:
That means I need to keep track of the last row imported, and start with that row += 1 the next time I would let the rake task run, how can I implement this?
Thanks in advance!