I have a simple rake task which consumes pretty much data via ActiveRecord. (contacts has ~47k rows)
Contact.all.each do |contact| contact.update_attribute ... end
When I run that task ~400 rows get updated and then the task stucks. No errors and no database activity at all…
How do I make this work properly?
This is exactly what find_in_batches is intended for. It will eliminate an enormous number of ActiveRecord objects in memory at once.
http://ryandaigle.com/articles/2009/2/23/what-s-new-in-edge-rails-batched-find