Description:
add grader stop, fix ARGV bug git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@19 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r6:f3b2d1128766 - - 1 file changed: 36 inserted, 4 deleted

@@ -78,30 +78,62
78 78
79 79 save_source(sub,problem_out_dir,source_name)
80 80 call_judge(problem_home,language,problem_out_dir,source_name)
81 81 save_result(sub,read_result("#{problem_out_dir}/test-result"))
82 82 end
83 83
84 - # reading environment
84 + def stop_grader
85 + File.open(File.dirname(__FILE__) + '/stop','w')
86 + end
87 +
88 + def check_stopfile
89 + FileTest.exist?(File.dirname(__FILE__) + '/stop')
90 + end
91 +
92 + def clear_stopfile
93 + system("rm " + File.dirname(__FILE__) + '/stop')
94 + end
95 +
96 + # reading environment and options
97 + if (ARGV.length >= 1) and (ARGV[0]=='stop')
98 + stop_grader
99 + puts "stop file created"
100 + exit(0)
101 + end
102 +
103 + if check_stopfile
104 + puts "stop file exists"
105 + clear_stopfile
106 + exit(0)
107 + end
108 +
109 + if ARGV.length >= 1
110 + GRADER_ENV = ARGV[0]
111 + else
85 112 GRADER_ENV = 'exam'
86 - if ARGV.length > 1
87 - GRADER_ENV = ARGV[1]
88 113 end
114 +
115 + puts "environment: #{GRADER_ENV}"
89 116 require File.dirname(__FILE__) + "/environment.rb"
90 117
91 118 #main program
92 -
93 119 talk 'Reading rails environment'
94 120
95 121 RAILS_ENV = 'development'
96 122 require RAILS_APP_DIR + '/config/environment'
97 123
98 124 current_dir = `pwd`
99 125
100 126 talk 'Grader queue'
101 127 while true
128 + if check_stopfile # created by calling grader stop
129 + clear_stopfile
130 + puts "stopped"
131 + exit(0)
132 + end
133 +
102 134 task = Task.find(:first, :order => 'created_at')
103 135 if task!=nil
104 136 grade(task.submission_id)
105 137 task.destroy
106 138 else
107 139 sleep(1)
You need to be logged in to leave comments. Login now