Skip to content

Instantly share code, notes, and snippets.

@wiseleyb
Last active August 29, 2015 13:57
Show Gist options
  • Save wiseleyb/9920795 to your computer and use it in GitHub Desktop.
Save wiseleyb/9920795 to your computer and use it in GitHub Desktop.
def run_action_credit_updates(batch, idx)
report_size = 10_000
batch.each_with_index do |b, i|
if i > 0 && i % report_size == 0
puts "Batch #{idx} : #{i} (#{ 100 - ((report_size/i.to_f) * 100).to_i }%)"
end
b.set_source_data
end
puts "Batch #{idx} : Done"
end
def update_action_credits
idx = 0
thecount = 0
threads = []
ActionCredit.
joins('LEFT OUTER JOIN action_credit_source_data ' +
'ON action_credits.id = action_credit_source_data.action_credit_id').
where('action_credit_source_data.id IS NULL').
where('action_credits.action in ("petition", "petition_signing")').
find_in_batches(batch_size: 200_000) do |batch|
thecount += batch.size
puts "#{batch.size} / #{thecount}"
idx += 1
threads << Thread.new{ run_action_credit_updates(batch, idx) }
end
threads.each_with_index do |t, idx|
puts "Joining thread #{idx}"
t.join
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment