Thursday, June 15, 2017

Rails: Active Record Timeout

Leave a Comment

This is a piece of code in place. When I add this to the cron with timeout the entire array gets saved twice. When I remove timeout nothing gets saved

In this scenario we would want to save the array results (coming in from an api) with over 100k records to be saved to the db. I have used bulk insert and TinyTds gems here

ActiveRecord::Base.establish_connection(adapter: 'sqlserver', host: "xxx", username: "xxx", password: "xxx", database: "xxx", azure: true, port: 1433, timeout: 5000)  class Report < ActiveRecord::Base   self.primary_key = 'id' end  my_array = [] #count of 100000 records Report.bulk_insert(:account_owner_id) do |worker|   my_array.drop(2).each do |arr|     worker.add account_owner_id: arr[0]   end end 

1 Answers

Answers 1

You can try removing timeout and adding ignore: true to your bulk insert as shown here. There may be an insert that is failing.

Report.bulk_insert(:account_owner_id, ignore: true) do |worker| 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment