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 @@ |
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 | 100 | |
101 | 101 | desc "Description here" |
102 | 102 | task(:question_vote_consistency => :environment) do |
103 | - questions = Question.find(:all) | |
104 | 103 | errors = [] |
105 | 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 | 109 | @question_tasks.each do |taskname, description| |
110 | + debug("Starting task #{taskname} for question #{question.id}") | |
110 | 111 | message, error_occurred = send(taskname, question) |
112 | + debug("Completed task #{taskname} for question #{question.id}") | |
111 | 113 | if error_occurred |
112 | 114 | errors << message |
113 | 115 | else |
... | ... | @@ -115,6 +117,7 @@ namespace :test_api do |
115 | 117 | end |
116 | 118 | end |
117 | 119 | |
120 | + debug("Starting choices tasks for question #{question.id}") | |
118 | 121 | question.choices.each do |choice| |
119 | 122 | @choice_tasks.each do |taskname, description| |
120 | 123 | message, error_occurred = send(taskname, choice) |
... | ... | @@ -125,11 +128,14 @@ namespace :test_api do |
125 | 128 | end |
126 | 129 | end |
127 | 130 | end |
131 | + debug("Completed choices tasks for question #{question.id}") | |
128 | 132 | |
129 | 133 | end |
130 | 134 | |
131 | 135 | @global_tasks.each do |taskname, description| |
136 | + debug("Starting global task #{taskname}") | |
132 | 137 | message, error_occurred = send(taskname) |
138 | + debug("Completed global task #{taskname}") | |
133 | 139 | if error_occurred |
134 | 140 | errors << message |
135 | 141 | else |
... | ... | @@ -137,7 +143,7 @@ namespace :test_api do |
137 | 143 | end |
138 | 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 | 147 | errors.each do |e| |
142 | 148 | email_text += " Test FAILED:\n" + e + "\n" |
143 | 149 | end |
... | ... | @@ -512,3 +518,11 @@ def cleanup_args(args) |
512 | 518 | end |
513 | 519 | a |
514 | 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 | ... | ... |