Show More
Commit Description:
Merged new-arch-branch changes 61:73 into the trunk...
Commit Description:
Merged new-arch-branch changes 61:73 into the trunk
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@74 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
grader
| 106 lines
| 1.9 KiB
| text/plain
| TextLexer
|
|
r0 | #!/usr/bin/ruby | ||
|
r6 | def stop_grader | ||
|
r7 | File.open(File.dirname(__FILE__) + '/stop','w').close | ||
|
r6 | end | ||
def check_stopfile | ||||
FileTest.exist?(File.dirname(__FILE__) + '/stop') | ||||
end | ||||
def clear_stopfile | ||||
system("rm " + File.dirname(__FILE__) + '/stop') | ||||
|
r0 | end | ||
|
r6 | |||
|
r22 | def config | ||
Grader::Configuration.get_instance | ||||
end | ||||
def talk(str) | ||||
if config.talkative | ||||
puts str | ||||
end | ||||
end | ||||
|
r11 | ######################################### | ||
# main program | ||||
######################################### | ||||
|
r6 | # reading environment and options | ||
if (ARGV.length >= 1) and (ARGV[0]=='stop') | ||||
stop_grader | ||||
puts "stop file created" | ||||
exit(0) | ||||
end | ||||
if check_stopfile | ||||
puts "stop file exists" | ||||
clear_stopfile | ||||
exit(0) | ||||
end | ||||
|
r9 | grader_mode = 'queue' | ||
|
r6 | if ARGV.length >= 1 | ||
GRADER_ENV = ARGV[0] | ||||
|
r9 | if ARGV.length >=2 | ||
grader_mode = ARGV[1] | ||||
end | ||||
|
r6 | else | ||
GRADER_ENV = 'exam' | ||||
end | ||||
puts "environment: #{GRADER_ENV}" | ||||
|
r22 | require File.join(File.dirname(__FILE__),'config/environment') | ||
|
r0 | |||
|
r20 | #reading rails environment | ||
|
r0 | talk 'Reading rails environment' | ||
|
r22 | RAILS_ENV = config.rails_env | ||
require RAILS_ROOT + '/config/environment' | ||||
|
r0 | |||
|
r20 | #register grader process | ||
|
r22 | if config.report_grader | ||
grader_proc = GraderProcess.register(config.grader_hostname, | ||||
|
r20 | Process.pid, | ||
grader_mode) | ||||
else | ||||
grader_proc = nil | ||||
end | ||||
|
r22 | # create judge engine | ||
engine = Grader::Engine.new(grader_proc) | ||||
|
r9 | case grader_mode | ||
when "queue" | ||||
talk 'Grader queue' | ||||
while true | ||||
|
r20 | |||
|
r9 | if check_stopfile # created by calling grader stop | ||
clear_stopfile | ||||
puts "stopped" | ||||
|
r22 | break | ||
|
r9 | end | ||
|
r20 | |||
|
r22 | task = engine.grade_oldest_task | ||
if task==nil | ||||
|
r20 | sleep(5) | ||
|
r9 | end | ||
end | ||||
when "prob" | ||||
|
r20 | |||
grader_proc.report_active if grader_proc!=nil | ||||
|
r9 | prob = Problem.find_by_name(ARGV[2]) | ||
if prob==nil | ||||
puts "cannot find problem: #{ARGV[2]}" | ||||
|
r22 | else | ||
engine.grade_problem(prob) | ||||
|
r6 | end | ||
|
r22 | |||
|
r0 | end | ||
|
r20 | # report inactive | ||
grader_proc.report_inactive if grader_proc!=nil | ||||
|
r9 | |||