Commit c390551c2d91bf73bded7116075040d26ec8e5b1

Authored by Luke Baker
1 parent d97a67f0

add comments in various places and fix bug

bug was in looking for length < 1000 instead of batchsize
Showing 1 changed file with 7 additions and 2 deletions   Show diff stats
lib/tasks/prune_db.rake
@@ -26,6 +26,8 @@ namespace :prune_db do @@ -26,6 +26,8 @@ namespace :prune_db do
26 end 26 end
27 end 27 end
28 28
  29 + # There is a very similar task in the AOI code base as well.
  30 + # Any core changes to this task should probably be reflected there.
29 desc "Converts all dates from PT to UTC" 31 desc "Converts all dates from PT to UTC"
30 task :convert_dates_to_utc, [:workerid, :workers] => [:environment] do|t,args| 32 task :convert_dates_to_utc, [:workerid, :workers] => [:environment] do|t,args|
31 args.with_defaults(:workerid => "0", :workers => "1") 33 args.with_defaults(:workerid => "0", :workers => "1")
@@ -109,6 +111,9 @@ namespace :prune_db do @@ -109,6 +111,9 @@ namespace :prune_db do
109 batch_size = 10000 111 batch_size = 10000
110 i = 0 112 i = 0
111 where = '' 113 where = ''
  114 + # This is how we split the rows of a table between the various workers
  115 + # so that they don't attempt to work on the same row as another worker.
  116 + # The workerid is any number 0 through workers - 1.
112 if args[:workers] > "1" 117 if args[:workers] > "1"
113 where = "WHERE MOD(id, #{args[:workers]}) = #{args[:workerid]}" 118 where = "WHERE MOD(id, #{args[:workers]}) = #{args[:workerid]}"
114 end 119 end
@@ -120,7 +125,7 @@ namespace :prune_db do @@ -120,7 +125,7 @@ namespace :prune_db do
120 125
121 rows.each do |row| 126 rows.each do |row|
122 updated_values = {} 127 updated_values = {}
123 - # delete any value where the value is blank 128 + # delete any value where the value is blank (just for delayed_jobs)
124 row.delete_if {|key, value| value.blank? } 129 row.delete_if {|key, value| value.blank? }
125 row.each do |column, value| 130 row.each do |column, value|
126 next if column == "id" 131 next if column == "id"
@@ -162,7 +167,7 @@ namespace :prune_db do @@ -162,7 +167,7 @@ namespace :prune_db do
162 end 167 end
163 168
164 i+= 1 169 i+= 1
165 - break if rows.length < 1000 170 + break if rows.length < batchsize
166 end 171 end
167 print "\n" 172 print "\n"
168 end 173 end