# HG changeset patch # User jittat # Date 2008-02-21 02:44:42 # Node ID 4c69afce24c0d4fa35e01f6d28682e20456494a8 # Parent 5d5b7e4073f524eaf589ef932c462a86abc054be 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 diff --git a/env_exam.rb.SAMPLE b/env_exam.rb.SAMPLE --- a/env_exam.rb.SAMPLE +++ b/env_exam.rb.SAMPLE @@ -5,6 +5,9 @@ TALKATIVE = true +REPORT_GRADER = true +GRADER_IP_ADDRESS = '158.108.111.111' + def report_comment(comment) if comment.chomp =~ /^P+$/ # all P's 'passed' diff --git a/env_grading.rb.SAMPLE b/env_grading.rb.SAMPLE --- a/env_grading.rb.SAMPLE +++ b/env_grading.rb.SAMPLE @@ -5,6 +5,9 @@ TALKATIVE = true +REPORT_GRADER = true +GRADER_IP_ADDRESS = '158.108.111.111' + def report_comment(comment) comment.chomp end diff --git a/grader b/grader --- a/grader +++ b/grader @@ -111,7 +111,7 @@ user_dir = "#{USER_RESULT_DIR}/#{user.login}" Dir.mkdir(user_dir) if !FileTest.exist?(user_dir) - problem_out_dir = "#{user_dir}/#{problem.name}" + problem_out_dir = "#{user_dir}/#{problem.name}/#{submission_id}" Dir.mkdir(problem_out_dir) if !FileTest.exist?(problem_out_dir) problem_home = "#{PROBLEMS_DIR}/#{problem.name}" @@ -171,32 +171,50 @@ puts "environment: #{GRADER_ENV}" require File.dirname(__FILE__) + "/environment.rb" -#main program +#reading rails environment talk 'Reading rails environment' RAILS_ENV = 'development' require RAILS_APP_DIR + '/config/environment' +#register grader process +if REPORT_GRADER + grader_proc = GraderProcess.register(GRADER_IP_ADDRESS, + Process.pid, + grader_mode) +else + grader_proc = nil +end + case grader_mode when "queue" talk 'Grader queue' while true + if check_stopfile # created by calling grader stop clear_stopfile puts "stopped" + grader_proc.report_inactive if grader_proc!=nil exit(0) end - task = Task.find(:first, :order => 'created_at') + task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) if task!=nil + grader_proc.report_active(task) if grader_proc!=nil + grade(task.submission_id) - task.destroy + task.status_complete else - sleep(1) + #grader_proc.report_active if grader_proc!=nil + + sleep(5) end end when "prob" + + grader_proc.report_active if grader_proc!=nil + prob = Problem.find_by_name(ARGV[2]) if prob==nil puts "cannot find problem: #{ARGV[2]}" @@ -215,7 +233,8 @@ end end - +# report inactive +grader_proc.report_inactive if grader_proc!=nil