-
-
Save rda1902/f3b7b4d017c55b7cffbd390fc50f2d82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| batches = Queue.new | |
| Order.select(:id).find_in_batches do |batch| | |
| batches << batch.map(&:id) | |
| end | |
| cpu_available.times do | |
| Thread.new do | |
| while(ids = batches.pop) | |
| pid = Process.fork do | |
| Sunspot.index! Order.includes(:product).find(ids) | |
| end | |
| Process.wait(pid) | |
| end | |
| end | |
| end | |
| Thread.new do | |
| sleep 1 until batches.size.zero? | |
| end.join | |
| Process.waitall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment