Description:
add more logging
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r174:09d1e857c1e3 - - 3 files changed: 17 inserted, 3 deleted
@@ -48,29 +48,32 | |||||
|
48 | using: (1) grader |
|
48 | using: (1) grader |
|
49 | (2) grader environment [mode] [options] |
|
49 | (2) grader environment [mode] [options] |
|
50 | (3) grader stop [all|pids-list] |
|
50 | (3) grader stop [all|pids-list] |
|
51 | (4) grader --help |
|
51 | (4) grader --help |
|
52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
52 | (1) call grader with environment = 'exam', mode = 'queue' |
|
53 | (2) possible modes are: 'queue', 'test_request', 'prob', 'sub', 'contest', and 'autonew' |
|
53 | (2) possible modes are: 'queue', 'test_request', 'prob', 'sub', 'contest', and 'autonew' |
|
54 | queue: repeatedly check the task queue and grade any available tasks |
|
54 | queue: repeatedly check the task queue and grade any available tasks |
|
55 |
|
55 | ||
|
56 | prob: re-grade every user latest submission of the specific problem. |
|
56 | prob: re-grade every user latest submission of the specific problem. |
|
57 | the problem name must be specified by the next argument. |
|
57 | the problem name must be specified by the next argument. |
|
58 |
|
58 | ||
|
59 | additional options: |
|
59 | additional options: |
|
|
60 | + --all-sub re-grade every submissions instead of just the latest submission of each user. | ||
|
60 |
|
61 | ||
|
61 | - --all-sub re-grade every submissions instead of just the latest submission of each user. |
|
||
|
62 | sub: re-grader the specified submission. |
|
62 | sub: re-grader the specified submission. |
|
63 | The submission ID to be re-graded must be specified by the next argument. |
|
63 | The submission ID to be re-graded must be specified by the next argument. |
|
64 |
|
64 | ||
|
|
65 | + options: | ||
|
|
66 | + --err-log log error to a file in the log dir | ||
|
|
67 | + | ||
|
65 | (3) create stop-file to stop running grader in queue mode |
|
68 | (3) create stop-file to stop running grader in queue mode |
|
66 | (4) You are here. |
|
69 | (4) You are here. |
|
67 | USAGE |
|
70 | USAGE |
|
68 | end |
|
71 | end |
|
69 |
|
72 | ||
|
70 | def process_options_and_stop_file |
|
73 | def process_options_and_stop_file |
|
71 | # The list of options are: |
|
74 | # The list of options are: |
|
72 | # - stop [all|process ids] |
|
75 | # - stop [all|process ids] |
|
73 | # - |
|
76 | # - |
|
74 |
|
77 | ||
|
75 | # Process 'help' option |
|
78 | # Process 'help' option |
|
76 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
|
79 | if (ARGV.length==1) and (/help/.match(ARGV[0])) |
@@ -125,24 +128,26 | |||||
|
125 | puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
128 | puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
126 | exit(0) |
|
129 | exit(0) |
|
127 | end |
|
130 | end |
|
128 |
|
131 | ||
|
129 | options[:report] = (ARGV.delete('--report') != nil) |
|
132 | options[:report] = (ARGV.delete('--report') != nil) |
|
130 | if options[:report] and (not ['prob','contest','autonew'].include? options[:mode]) |
|
133 | if options[:report] and (not ['prob','contest','autonew'].include? options[:mode]) |
|
131 | puts "Report currently works only for 'prob' or 'contest' modes." |
|
134 | puts "Report currently works only for 'prob' or 'contest' modes." |
|
132 | exit(0) |
|
135 | exit(0) |
|
133 | end |
|
136 | end |
|
134 |
|
137 | ||
|
135 | options[:all_sub] = (ARGV.delete('--all-sub') != nil) |
|
138 | options[:all_sub] = (ARGV.delete('--all-sub') != nil) |
|
136 |
|
139 | ||
|
|
140 | + options[:err_log] = (ARGV.delete('--err-log') != nil) | ||
|
|
141 | + | ||
|
137 | return options |
|
142 | return options |
|
138 | end |
|
143 | end |
|
139 |
|
144 | ||
|
140 | class ResultCollector |
|
145 | class ResultCollector |
|
141 | def initialize |
|
146 | def initialize |
|
142 | @results = {} |
|
147 | @results = {} |
|
143 | @problems = {} |
|
148 | @problems = {} |
|
144 | @users = {} |
|
149 | @users = {} |
|
145 | end |
|
150 | end |
|
146 |
|
151 | ||
|
147 | def after_save_hook(submission, grading_result) |
|
152 | def after_save_hook(submission, grading_result) |
|
148 | end |
|
153 | end |
@@ -411,24 +416,31 | |||||
|
411 |
|
416 | ||
|
412 | # register grader process |
|
417 | # register grader process |
|
413 | if config.report_grader |
|
418 | if config.report_grader |
|
414 | grader_proc = GraderProcess.register(config.grader_hostname, |
|
419 | grader_proc = GraderProcess.register(config.grader_hostname, |
|
415 | Process.pid, |
|
420 | Process.pid, |
|
416 | grader_mode) |
|
421 | grader_mode) |
|
417 | else |
|
422 | else |
|
418 | grader_proc = nil |
|
423 | grader_proc = nil |
|
419 | end |
|
424 | end |
|
420 |
|
425 | ||
|
421 | #set loggin environment |
|
426 | #set loggin environment |
|
422 | ENV['GRADER_LOGGING'] = log_file_name |
|
427 | ENV['GRADER_LOGGING'] = log_file_name |
|
|
428 | + if options[:err_log] | ||
|
|
429 | + err_file_name = log_file_name + '.err' | ||
|
|
430 | + $stderr.reopen(err_file_name,"a") | ||
|
|
431 | + log "STDERR log to file [#{err_file_name}]" | ||
|
|
432 | + warn "start logging for grader PID #{Process.id} on #{Time.now.in_time_zone}" | ||
|
|
433 | + end | ||
|
|
434 | + | ||
|
423 |
|
435 | ||
|
424 | # register exit handler to report inactive, and terminated |
|
436 | # register exit handler to report inactive, and terminated |
|
425 | at_exit do |
|
437 | at_exit do |
|
426 | if grader_proc!=nil |
|
438 | if grader_proc!=nil |
|
427 | grader_proc.report_inactive |
|
439 | grader_proc.report_inactive |
|
428 | grader_proc.terminate |
|
440 | grader_proc.terminate |
|
429 | end |
|
441 | end |
|
430 | end |
|
442 | end |
|
431 |
|
443 | ||
|
432 | # |
|
444 | # |
|
433 | # MAIN LOOP |
|
445 | # MAIN LOOP |
|
434 | # |
|
446 | # |
@@ -109,26 +109,28 | |||||
|
109 | def talk(str) |
|
109 | def talk(str) |
|
110 | if @config.talkative |
|
110 | if @config.talkative |
|
111 | puts str |
|
111 | puts str |
|
112 | end |
|
112 | end |
|
113 | end |
|
113 | end |
|
114 |
|
114 | ||
|
115 | def call_judge(problem_home,language,grading_dir,fname) |
|
115 | def call_judge(problem_home,language,grading_dir,fname) |
|
116 | ENV['PROBLEM_HOME'] = problem_home |
|
116 | ENV['PROBLEM_HOME'] = problem_home |
|
117 | ENV['RUBYOPT'] = '' |
|
117 | ENV['RUBYOPT'] = '' |
|
118 |
|
118 | ||
|
119 | talk grading_dir |
|
119 | talk grading_dir |
|
120 | Dir.chdir grading_dir |
|
120 | Dir.chdir grading_dir |
|
121 |
- |
|
121 | + script_name = "#{problem_home}/script/judge" |
|
|
122 | + cmd = "#{script_name} #{language} #{fname}" | ||
|
122 | talk "CMD: #{cmd}" |
|
123 | talk "CMD: #{cmd}" |
|
|
124 | + warn "ERROR: file does not exists #{script_name}" unless File.exists? script_name | ||
|
123 | system(cmd) |
|
125 | system(cmd) |
|
124 | end |
|
126 | end |
|
125 |
|
127 | ||
|
126 | def get_std_script_dir |
|
128 | def get_std_script_dir |
|
127 | GRADER_ROOT + '/std-script' |
|
129 | GRADER_ROOT + '/std-script' |
|
128 | end |
|
130 | end |
|
129 |
|
131 | ||
|
130 | def copy_script(problem_home) |
|
132 | def copy_script(problem_home) |
|
131 | script_dir = "#{problem_home}/script" |
|
133 | script_dir = "#{problem_home}/script" |
|
132 | std_script_dir = get_std_script_dir |
|
134 | std_script_dir = get_std_script_dir |
|
133 |
|
135 | ||
|
134 | raise "engine: std-script directory not found" if !FileTest.exist?(std_script_dir) |
|
136 | raise "engine: std-script directory not found" if !FileTest.exist?(std_script_dir) |
@@ -36,25 +36,25 | |||||
|
36 | @engine.grade(sub) |
|
36 | @engine.grade(sub) |
|
37 | end |
|
37 | end |
|
38 | else |
|
38 | else |
|
39 | last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id) |
|
39 | last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id) |
|
40 | if last_sub!=nil |
|
40 | if last_sub!=nil |
|
41 | @engine.grade(last_sub) |
|
41 | @engine.grade(last_sub) |
|
42 | end |
|
42 | end |
|
43 | end |
|
43 | end |
|
44 | end |
|
44 | end |
|
45 | end |
|
45 | end |
|
46 |
|
46 | ||
|
47 | def grade_submission(submission) |
|
47 | def grade_submission(submission) |
|
48 | - puts "Submission: #{submission.id} by #{submission.user.full_name}" |
|
48 | + puts "Submission: #{submission.id} by #{submission.try(:user).try(:full_name)}" |
|
49 | @engine.grade(submission) |
|
49 | @engine.grade(submission) |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | def grade_oldest_test_request |
|
52 | def grade_oldest_test_request |
|
53 | test_request = TestRequest.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
53 | test_request = TestRequest.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
54 | if test_request!=nil |
|
54 | if test_request!=nil |
|
55 | @grader_process.report_active(test_request) if @grader_process!=nil |
|
55 | @grader_process.report_active(test_request) if @grader_process!=nil |
|
56 |
|
56 | ||
|
57 | @engine.grade(test_request) |
|
57 | @engine.grade(test_request) |
|
58 | test_request.status_complete! |
|
58 | test_request.status_complete! |
|
59 | @grader_process.report_inactive(test_request) if @grader_process!=nil |
|
59 | @grader_process.report_inactive(test_request) if @grader_process!=nil |
|
60 | end |
|
60 | end |
You need to be logged in to leave comments.
Login now