dimanche 10 juillet 2016

To update all the records that are growing in number in Rails

I'm using MySQL, and Rails 4.2.3. I've a table called onwers, and it's gonna keep growing for 2 weeks, as there is background job that is feeding it all the time.

Now, I'd like to update all Onwer records in Rails, and the following is the way that I'm accomplishing the job:

Owner.find_each(batch_size: 100) do |owner|
  Owner.get_owner_details_from_github owner.login
end

What would be the best way to write code that will keep doing its job? On one hand, it's gonna populate owners table, and on the other, no matter how many records are there in owners, the code will do its job.

Aucun commentaire:

Enregistrer un commentaire