Skip to content

Instantly share code, notes, and snippets.

@foreverman
Created August 31, 2011 14:30
Show Gist options
  • Save foreverman/1183675 to your computer and use it in GitHub Desktop.
Save foreverman/1183675 to your computer and use it in GitHub Desktop.
jobs_per_process = 100
process_count = 10
User.find_in_batches(:batch_size => jobs_per_process * process_count) do |group|
batches = group.in_groups(process_count)
Parallel.each(batches, :in_processes => process_count) do |batch|
ActiveRecord::Base.establish_connection
# Do the actual work
batch.each {|user| .. }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment