Rails Version: 4.2.7
Ruby Version: 2.3.3
I am running a rake task to migrate several million objects from CSV and JSON file format into my postgres database.
I was attempting to utilize activerecord-import
to speed up writing the objects to the database.
Simplifying the code down as much as possible, the first half dealt with object type one (which came from one data type) and the second half dealt with object type two.
The first object type iterated like so (simplified for the question):
importing_object_one_array = []
my_external_data.each do |element|
new_element = ObjectOne.new(
title: element[0],
body: element[1]
)
importing_object_one_array << new_element
end
ObjectOne.import importing_object_one_array, validate: false
This ran on roughly 250,000 objects, and wrote without a any issues, I've inspected in the console and the objects are successfully written.
However, object type two has a fair few extra objects, each roughly the same size and design as object type one.
There are roughly 4,040,000 of these.
How long should I wait for ObjectTwo.import
to run? We're into hours now.
Alternatively, from a debugging perspective (as I would really rather not re-run this rake task unless I absolutely have to), what scripts or tactics would be useful to see if ObjectTwo.import
really is currently running (even if it's taking forever) or if the task is hanging?
I inspected the rails console and we appear to still be at the same number of ObjectTwo
's in the database as before.
My only other thought is that as I didn't print out to the console before running #import
(i.e. like puts "Now starting import!"
) I don't have 100% proof that the objects building in the array has finished.