Created
April 1, 2014 23:03
-
-
Save wiseleyb/9924879 to your computer and use it in GitHub Desktop.
This file contains 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
# ---------------------------------------------------------------- | |
# FILE: launch_action_credits.rb | |
# ---------------------------------------------------------------- | |
# launch action credits | |
# to launch: prodrunner ~/launch_action_credits.rb | |
object_count = 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")'). | |
count | |
steps = 50 | |
step_size = (object_count + 1000) / steps | |
session_name = 'update_action_credits' | |
script_name = '~/update_action_credits.rb' | |
`tmux new-session -d -s#{session_name} -n0` | |
(steps - 1).times do |i| | |
`tmux new-window -t#{session_name}:#{i+1} -n#{i+1}` | |
end | |
batch_count = 0 | |
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")'). | |
select('action_credits.id'). | |
find_in_batches(batch_size: step_size) do |batch| | |
first_id = batch.first.id | |
last_id = batch.last.id | |
puts "#{batch_count} #{first_id}, #{last_id} ... #{last_id - first_id} ... #{batch.size}" | |
`tmux send-keys -t#{session_name}:#{batch_count} 'prodrunner #{script_name} #{first_id} #{last_id}' C-m` | |
puts 'sleeping for 60' | |
sleep 60 | |
end | |
puts "You've creates #{steps} tmux windows in session #{session_name}" | |
puts `tmux ls` | |
puts "" | |
puts "You can tmux in via:" | |
puts "tmux at -t#{session_name}" | |
puts "" | |
puts "You can select windows once in tmux via:" | |
puts "ctrl-b-w" | |
puts "" | |
puts "And you can detach back to console:" | |
puts "ctrl-b-d" | |
puts "" | |
puts "And you can kill off this via:" | |
puts "tmux kill-session -t#{session_name}" | |
# ---------------------------------------------------------------- | |
# FILE: update_action_credits.rb | |
# ---------------------------------------------------------------- | |
# update action credits | |
MigrationTools::Utils.silence! | |
ARGV.delete("-e") | |
ARGV.delete("prodrw") | |
start_id = ARGV.first.to_i | |
end_id = ARGV.second.to_i | |
#start_id = 1103897 | |
#end_id = 54636527 | |
counter = 0 | |
total_count = ActionCredit.where('id >= ? and id <= ?', start_id, end_id).count | |
report_size = 10_000 | |
ActionCredit.where('id >= ? and id <= ?', start_id, end_id).find_each do |ac| | |
counter += 1 | |
if counter % report_size == 0 | |
puts "#{counter} / #{total_count} #{ ((counter / total_count.to_f) * 100).to_i }%" | |
end | |
ac.set_source_data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment