Commit 1da85d1e041eb7b1a998f52e104cc65807c045ba
1 parent
2bd88b0f
Exists in
master
and in
1 other branch
add debug logging and find questions in batches of 3
Showing
2 changed files
with
23 additions
and
3 deletions
Show diff stats
@@ -0,0 +1,6 @@ | @@ -0,0 +1,6 @@ | ||
1 | +class AuditLogger < Logger | ||
2 | + def format_message(severity, timestamp, progname, msg) | ||
3 | + pid, size = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{Process::pid}"`.chomp.split(/\s+/).map {|s| s.strip.to_i} | ||
4 | + "[#{timestamp.to_formatted_s(:db)}] [#{severity}] [#{size} KB] #{msg}\n" | ||
5 | + end | ||
6 | +end |
lib/tasks/test_api.rake
@@ -100,14 +100,16 @@ namespace :test_api do | @@ -100,14 +100,16 @@ namespace :test_api do | ||
100 | 100 | ||
101 | desc "Description here" | 101 | desc "Description here" |
102 | task(:question_vote_consistency => :environment) do | 102 | task(:question_vote_consistency => :environment) do |
103 | - questions = Question.find(:all) | ||
104 | errors = [] | 103 | errors = [] |
105 | successes = [] | 104 | successes = [] |
106 | 105 | ||
107 | - questions.each do |question| | 106 | + Question.find_each(:batch_size => 3) do |question| |
108 | 107 | ||
108 | + debug("Starting tasks for question #{question.id}") | ||
109 | @question_tasks.each do |taskname, description| | 109 | @question_tasks.each do |taskname, description| |
110 | + debug("Starting task #{taskname} for question #{question.id}") | ||
110 | message, error_occurred = send(taskname, question) | 111 | message, error_occurred = send(taskname, question) |
112 | + debug("Completed task #{taskname} for question #{question.id}") | ||
111 | if error_occurred | 113 | if error_occurred |
112 | errors << message | 114 | errors << message |
113 | else | 115 | else |
@@ -115,6 +117,7 @@ namespace :test_api do | @@ -115,6 +117,7 @@ namespace :test_api do | ||
115 | end | 117 | end |
116 | end | 118 | end |
117 | 119 | ||
120 | + debug("Starting choices tasks for question #{question.id}") | ||
118 | question.choices.each do |choice| | 121 | question.choices.each do |choice| |
119 | @choice_tasks.each do |taskname, description| | 122 | @choice_tasks.each do |taskname, description| |
120 | message, error_occurred = send(taskname, choice) | 123 | message, error_occurred = send(taskname, choice) |
@@ -125,11 +128,14 @@ namespace :test_api do | @@ -125,11 +128,14 @@ namespace :test_api do | ||
125 | end | 128 | end |
126 | end | 129 | end |
127 | end | 130 | end |
131 | + debug("Completed choices tasks for question #{question.id}") | ||
128 | 132 | ||
129 | end | 133 | end |
130 | 134 | ||
131 | @global_tasks.each do |taskname, description| | 135 | @global_tasks.each do |taskname, description| |
136 | + debug("Starting global task #{taskname}") | ||
132 | message, error_occurred = send(taskname) | 137 | message, error_occurred = send(taskname) |
138 | + debug("Completed global task #{taskname}") | ||
133 | if error_occurred | 139 | if error_occurred |
134 | errors << message | 140 | errors << message |
135 | else | 141 | else |
@@ -137,7 +143,7 @@ namespace :test_api do | @@ -137,7 +143,7 @@ namespace :test_api do | ||
137 | end | 143 | end |
138 | end | 144 | end |
139 | 145 | ||
140 | - email_text = "Conducted the following tests on API data and found the following results\n" + "For each of the #{questions.length} questions in the database: \n" | 146 | + email_text = "Conducted the following tests on API data and found the following results\n" + "For each of the #{Question.all.count} questions in the database: \n" |
141 | errors.each do |e| | 147 | errors.each do |e| |
142 | email_text += " Test FAILED:\n" + e + "\n" | 148 | email_text += " Test FAILED:\n" + e + "\n" |
143 | end | 149 | end |
@@ -512,3 +518,11 @@ def cleanup_args(args) | @@ -512,3 +518,11 @@ def cleanup_args(args) | ||
512 | end | 518 | end |
513 | a | 519 | a |
514 | end | 520 | end |
521 | + | ||
522 | +def debug(message) | ||
523 | + return unless ENV['debug'] == 'true' | ||
524 | + if defined?(Rails) | ||
525 | + logger = AuditLogger.new(STDOUT) | ||
526 | + logger.info(message) | ||
527 | + end | ||
528 | +end |