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 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
2 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
3 |
|
3 | ||
|
4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
5 |
|
5 | ||
|
6 | TALKATIVE = true |
|
6 | TALKATIVE = true |
|
7 |
|
7 | ||
|
|
8 | + REPORT_GRADER = true | ||
|
|
9 | + GRADER_IP_ADDRESS = '158.108.111.111' | ||
|
|
10 | + | ||
|
8 | def report_comment(comment) |
|
11 | def report_comment(comment) |
|
9 | if comment.chomp =~ /^P+$/ # all P's |
|
12 | if comment.chomp =~ /^P+$/ # all P's |
|
10 | 'passed' |
|
13 | 'passed' |
|
11 | else |
|
14 | else |
|
12 | 'failed' |
|
15 | 'failed' |
|
13 | end |
|
16 | end |
|
14 | end |
|
17 | end |
@@ -1,10 +1,13 | |||||
|
1 |
|
1 | ||
|
2 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
2 | PROBLEMS_DIR = "/home/jittat/grader/ev" |
|
3 |
|
3 | ||
|
4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
4 | USER_RESULT_DIR = "/home/jittat/grader/result" |
|
5 |
|
5 | ||
|
6 | TALKATIVE = true |
|
6 | TALKATIVE = true |
|
7 |
|
7 | ||
|
|
8 | + REPORT_GRADER = true | ||
|
|
9 | + GRADER_IP_ADDRESS = '158.108.111.111' | ||
|
|
10 | + | ||
|
8 | def report_comment(comment) |
|
11 | def report_comment(comment) |
|
9 | comment.chomp |
|
12 | comment.chomp |
|
10 | end |
|
13 | end |
@@ -90,49 +90,49 | |||||
|
90 | def clear_script(log,problem_home) |
|
90 | def clear_script(log,problem_home) |
|
91 | log.each do |s| |
|
91 | log.each do |s| |
|
92 | system("rm #{problem_home}/script/#{s}") |
|
92 | system("rm #{problem_home}/script/#{s}") |
|
93 | end |
|
93 | end |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | def grade(submission_id) |
|
96 | def grade(submission_id) |
|
97 | current_dir = `pwd`.chomp |
|
97 | current_dir = `pwd`.chomp |
|
98 |
|
98 | ||
|
99 | sub = Submission.find(submission_id) |
|
99 | sub = Submission.find(submission_id) |
|
100 | user = sub.user |
|
100 | user = sub.user |
|
101 | problem = sub.problem |
|
101 | problem = sub.problem |
|
102 |
|
102 | ||
|
103 | language = sub.language.name |
|
103 | language = sub.language.name |
|
104 | lang_ext = sub.language.ext |
|
104 | lang_ext = sub.language.ext |
|
105 | # FIX THIS |
|
105 | # FIX THIS |
|
106 | talk 'some hack on language' |
|
106 | talk 'some hack on language' |
|
107 | if language == 'cpp' |
|
107 | if language == 'cpp' |
|
108 | language = 'c++' |
|
108 | language = 'c++' |
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
111 | user_dir = "#{USER_RESULT_DIR}/#{user.login}" |
|
112 | Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) |
|
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 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
115 | Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) |
|
116 |
|
116 | ||
|
117 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
117 | problem_home = "#{PROBLEMS_DIR}/#{problem.name}" |
|
118 | source_name = "#{problem.name}.#{lang_ext}" |
|
118 | source_name = "#{problem.name}.#{lang_ext}" |
|
119 |
|
119 | ||
|
120 | save_source(sub,problem_out_dir,source_name) |
|
120 | save_source(sub,problem_out_dir,source_name) |
|
121 |
|
121 | ||
|
122 | copy_log = copy_script(problem_home) |
|
122 | copy_log = copy_script(problem_home) |
|
123 |
|
123 | ||
|
124 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
124 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
125 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
125 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
126 |
|
126 | ||
|
127 | clear_script(copy_log,problem_home) |
|
127 | clear_script(copy_log,problem_home) |
|
128 |
|
128 | ||
|
129 | Dir.chdir(current_dir) |
|
129 | Dir.chdir(current_dir) |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | def stop_grader |
|
132 | def stop_grader |
|
133 | File.open(File.dirname(__FILE__) + '/stop','w').close |
|
133 | File.open(File.dirname(__FILE__) + '/stop','w').close |
|
134 | end |
|
134 | end |
|
135 |
|
135 | ||
|
136 | def check_stopfile |
|
136 | def check_stopfile |
|
137 | FileTest.exist?(File.dirname(__FILE__) + '/stop') |
|
137 | FileTest.exist?(File.dirname(__FILE__) + '/stop') |
|
138 | end |
|
138 | end |
@@ -150,72 +150,91 | |||||
|
150 | stop_grader |
|
150 | stop_grader |
|
151 | puts "stop file created" |
|
151 | puts "stop file created" |
|
152 | exit(0) |
|
152 | exit(0) |
|
153 | end |
|
153 | end |
|
154 |
|
154 | ||
|
155 | if check_stopfile |
|
155 | if check_stopfile |
|
156 | puts "stop file exists" |
|
156 | puts "stop file exists" |
|
157 | clear_stopfile |
|
157 | clear_stopfile |
|
158 | exit(0) |
|
158 | exit(0) |
|
159 | end |
|
159 | end |
|
160 |
|
160 | ||
|
161 | grader_mode = 'queue' |
|
161 | grader_mode = 'queue' |
|
162 | if ARGV.length >= 1 |
|
162 | if ARGV.length >= 1 |
|
163 | GRADER_ENV = ARGV[0] |
|
163 | GRADER_ENV = ARGV[0] |
|
164 | if ARGV.length >=2 |
|
164 | if ARGV.length >=2 |
|
165 | grader_mode = ARGV[1] |
|
165 | grader_mode = ARGV[1] |
|
166 | end |
|
166 | end |
|
167 | else |
|
167 | else |
|
168 | GRADER_ENV = 'exam' |
|
168 | GRADER_ENV = 'exam' |
|
169 | end |
|
169 | end |
|
170 |
|
170 | ||
|
171 | puts "environment: #{GRADER_ENV}" |
|
171 | puts "environment: #{GRADER_ENV}" |
|
172 | require File.dirname(__FILE__) + "/environment.rb" |
|
172 | require File.dirname(__FILE__) + "/environment.rb" |
|
173 |
|
173 | ||
|
174 | - #main program |
|
174 | + #reading rails environment |
|
175 | talk 'Reading rails environment' |
|
175 | talk 'Reading rails environment' |
|
176 |
|
176 | ||
|
177 | RAILS_ENV = 'development' |
|
177 | RAILS_ENV = 'development' |
|
178 | require RAILS_APP_DIR + '/config/environment' |
|
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 | case grader_mode |
|
189 | case grader_mode |
|
181 | when "queue" |
|
190 | when "queue" |
|
182 | talk 'Grader queue' |
|
191 | talk 'Grader queue' |
|
183 | while true |
|
192 | while true |
|
|
193 | + | ||
|
184 | if check_stopfile # created by calling grader stop |
|
194 | if check_stopfile # created by calling grader stop |
|
185 | clear_stopfile |
|
195 | clear_stopfile |
|
186 | puts "stopped" |
|
196 | puts "stopped" |
|
|
197 | + grader_proc.report_inactive if grader_proc!=nil | ||
|
187 | exit(0) |
|
198 | exit(0) |
|
188 | end |
|
199 | end |
|
189 |
|
200 | ||
|
190 | - task = Task.find(:first, :order => 'created_at') |
|
201 | + task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
191 | if task!=nil |
|
202 | if task!=nil |
|
|
203 | + grader_proc.report_active(task) if grader_proc!=nil | ||
|
|
204 | + | ||
|
192 | grade(task.submission_id) |
|
205 | grade(task.submission_id) |
|
193 |
- task. |
|
206 | + task.status_complete |
|
194 | else |
|
207 | else |
|
195 | - sleep(1) |
|
208 | + #grader_proc.report_active if grader_proc!=nil |
|
|
209 | + | ||
|
|
210 | + sleep(5) | ||
|
196 | end |
|
211 | end |
|
197 | end |
|
212 | end |
|
198 |
|
213 | ||
|
199 | when "prob" |
|
214 | when "prob" |
|
|
215 | + | ||
|
|
216 | + grader_proc.report_active if grader_proc!=nil | ||
|
|
217 | + | ||
|
200 | prob = Problem.find_by_name(ARGV[2]) |
|
218 | prob = Problem.find_by_name(ARGV[2]) |
|
201 | if prob==nil |
|
219 | if prob==nil |
|
202 | puts "cannot find problem: #{ARGV[2]}" |
|
220 | puts "cannot find problem: #{ARGV[2]}" |
|
203 | exit(0) |
|
221 | exit(0) |
|
204 | end |
|
222 | end |
|
205 | users = User.find(:all) |
|
223 | users = User.find(:all) |
|
206 | users.each do |u| |
|
224 | users.each do |u| |
|
207 | puts "user: #{u.login}" |
|
225 | puts "user: #{u.login}" |
|
208 | last_sub = Submission.find(:first, |
|
226 | last_sub = Submission.find(:first, |
|
209 | :conditions => "user_id = #{u.id} and " + |
|
227 | :conditions => "user_id = #{u.id} and " + |
|
210 | "problem_id = #{prob.id}", |
|
228 | "problem_id = #{prob.id}", |
|
211 | :order => 'submitted_at DESC') |
|
229 | :order => 'submitted_at DESC') |
|
212 | if last_sub!=nil |
|
230 | if last_sub!=nil |
|
213 | grade(last_sub.id) |
|
231 | grade(last_sub.id) |
|
214 | end |
|
232 | end |
|
215 | end |
|
233 | end |
|
216 | end |
|
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