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