A bit of context before going to the solution...
I was trying to call a bulk insertion of some objects in the database in a Rails app hosted in Heroku, taking data from an user uploaded CSV file and processing it via
find_or_create_by for each row, updating all the attributes when necessary and finally persisting the data in the database.
As the data rows grew in number (over 5k entries usually) the timeout limit of 30 seconds imposed by Heroku wasn't enough. So I had to setup the delayed_job gem with the HireFire gem for a cheaper experience in Heroku for the bulk process.
So I did it this way.
TheModel.delay.import_from_csv params[:file] # The offending line
redirect_to root_url, notice: 'Data inserted successfully'
CSV.foreach(file_path, headers: true) do |row|
temp_stuff = row.to_hash
the_model = TheModel.find_or_create_by(:attribute1 => temp_stuff['attribute1'])
# ... fill with data
With the delayed_job ruby gem I was always getting