Description:
add task queue access control, grader status
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@58 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r20:4c69afce24c0 - - 3 files changed: 31 inserted, 6 deleted
@@ -1,14 +1,17 | |||
|
1 | 1 | |
|
2 | 2 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
3 | 3 | |
|
4 | 4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
5 | 5 | |
|
6 | 6 | TALKATIVE = true |
|
7 | 7 | |
|
8 | + REPORT_GRADER = true | |
|
9 | + GRADER_IP_ADDRESS = '158.108.111.111' | |
|
10 | + | |
|
8 | 11 | def report_comment(comment) |
|
9 | 12 | if comment.chomp =~ /^P+$/ # all P's |
|
10 | 13 | 'passed' |
|
11 | 14 | else |
|
12 | 15 | 'failed' |
|
13 | 16 | end |
|
14 | 17 | end |
@@ -1,10 +1,13 | |||
|
1 | 1 | |
|
2 | 2 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
3 | 3 | |
|
4 | 4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
5 | 5 | |
|
6 | 6 | TALKATIVE = true |
|
7 | 7 | |
|
8 | + REPORT_GRADER = true | |
|
9 | + GRADER_IP_ADDRESS = '158.108.111.111' | |
|
10 | + | |
|
8 | 11 | def report_comment(comment) |
|
9 | 12 | comment.chomp |
|
10 | 13 | end |
@@ -102,25 +102,25 | |||
|
102 | 102 | |
|
103 | 103 | language = sub.language.name |
|
104 | 104 | lang_ext = sub.language.ext |
|
105 | 105 | # FIX THIS |
|
106 | 106 | talk 'some hack on language' |
|
107 | 107 | if language == 'cpp' |
|
108 | 108 | language = 'c++' |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
112 | 112 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
113 | 113 | |
|
114 | - problem_out_dir = "#{user_dir}/#{problem.name}" | |
|
114 | + problem_out_dir = "#{user_dir}/#{problem.name}/#{submission_id}" | |
|
115 | 115 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
116 | 116 | |
|
117 | 117 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
118 | 118 | source_name = "#{problem.name}.#{lang_ext}" |
|
119 | 119 | |
|
120 | 120 | save_source(sub,problem_out_dir,source_name) |
|
121 | 121 | |
|
122 | 122 | copy_log = copy_script(problem_home) |
|
123 | 123 | |
|
124 | 124 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
125 | 125 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
126 | 126 | |
@@ -162,60 +162,79 | |||
|
162 | 162 | if ARGV.length >= 1 |
|
163 | 163 | GRADER_ENV = ARGV[0] |
|
164 | 164 | if ARGV.length >=2 |
|
165 | 165 | grader_mode = ARGV[1] |
|
166 | 166 | end |
|
167 | 167 | else |
|
168 | 168 | GRADER_ENV = 'exam' |
|
169 | 169 | end |
|
170 | 170 | |
|
171 | 171 | puts "environment: #{GRADER_ENV}" |
|
172 | 172 | require File.dirname(__FILE__) + "/environment.rb" |
|
173 | 173 | |
|
174 | - #main program | |
|
174 | + #reading rails environment | |
|
175 | 175 | talk 'Reading rails environment' |
|
176 | 176 | |
|
177 | 177 | RAILS_ENV = 'development' |
|
178 | 178 | require RAILS_APP_DIR + '/config/environment' |
|
179 | 179 | |
|
180 | + #register grader process | |
|
181 | + if REPORT_GRADER | |
|
182 | + grader_proc = GraderProcess.register(GRADER_IP_ADDRESS, | |
|
183 | + Process.pid, | |
|
184 | + grader_mode) | |
|
185 | + else | |
|
186 | + grader_proc = nil | |
|
187 | + end | |
|
188 | + | |
|
180 | 189 | case grader_mode |
|
181 | 190 | when "queue" |
|
182 | 191 | talk 'Grader queue' |
|
183 | 192 | while true |
|
193 | + | |
|
184 | 194 | if check_stopfile # created by calling grader stop |
|
185 | 195 | clear_stopfile |
|
186 | 196 | puts "stopped" |
|
197 | + grader_proc.report_inactive if grader_proc!=nil | |
|
187 | 198 | exit(0) |
|
188 | 199 | end |
|
189 | 200 | |
|
190 | - task = Task.find(:first, :order => 'created_at') | |
|
201 | + task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) | |
|
191 | 202 | if task!=nil |
|
203 | + grader_proc.report_active(task) if grader_proc!=nil | |
|
204 | + | |
|
192 | 205 | grade(task.submission_id) |
|
193 |
- task. |
|
|
206 | + task.status_complete | |
|
194 | 207 | else |
|
195 | - sleep(1) | |
|
208 | + #grader_proc.report_active if grader_proc!=nil | |
|
209 | + | |
|
210 | + sleep(5) | |
|
196 | 211 | end |
|
197 | 212 | end |
|
198 | 213 | |
|
199 | 214 | when "prob" |
|
215 | + | |
|
216 | + grader_proc.report_active if grader_proc!=nil | |
|
217 | + | |
|
200 | 218 | prob = Problem.find_by_name(ARGV[2]) |
|
201 | 219 | if prob==nil |
|
202 | 220 | puts "cannot find problem: #{ARGV[2]}" |
|
203 | 221 | exit(0) |
|
204 | 222 | end |
|
205 | 223 | users = User.find(:all) |
|
206 | 224 | users.each do |u| |
|
207 | 225 | puts "user: #{u.login}" |
|
208 | 226 | last_sub = Submission.find(:first, |
|
209 | 227 | :conditions => "user_id = #{u.id} and " + |
|
210 | 228 | "problem_id = #{prob.id}", |
|
211 | 229 | :order => 'submitted_at DESC') |
|
212 | 230 | if last_sub!=nil |
|
213 | 231 | grade(last_sub.id) |
|
214 | 232 | end |
|
215 | 233 | end |
|
216 | 234 | end |
|
217 | 235 | |
|
218 | - | |
|
236 | + # report inactive | |
|
237 | + grader_proc.report_inactive if grader_proc!=nil | |
|
219 | 238 | |
|
220 | 239 | |
|
221 | 240 |
You need to be logged in to leave comments.
Login now