diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -2,7 +2,11 @@ before_filter :admin_authorization - verify :method => :post, :only => ['clear_all', 'clear_terminated'], + verify :method => :post, :only => ['clear_all', + 'start_exam', + 'start_grading', + 'stop_all', + 'clear_terminated'], :redirect_to => {:action => 'index'} def index @@ -65,18 +69,28 @@ def stop grader_proc = GraderProcess.find(params[:id]) - stop_grader(grader_proc.pid) + GraderScript.stop_grader(grader_proc.pid) + flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.' + redirect_to :action => 'list' + end + + def stop_all + GraderScript.stop_graders(GraderProcess.find_running_graders + + GraderProcess.find_stalled_process) + flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.' redirect_to :action => 'list' end - - protected + def start_grading + GraderScript.start_grader('grading') + flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request' + redirect_to :action => 'list' + end - def stop_grader(pid) - if GraderProcess.grader_control_enabled? - cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}" - system(cmd) - end + def start_exam + GraderScript.start_grader('exam') + flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request' + redirect_to :action => 'list' end end diff --git a/app/models/grader_process.rb b/app/models/grader_process.rb --- a/app/models/grader_process.rb +++ b/app/models/grader_process.rb @@ -43,14 +43,6 @@ Time.now.gmtime - GraderProcess.stalled_time]) end - def self.grader_control_enabled? - if defined? GRADER_SCRIPT_DIR - GRADER_SCRIPT_DIR != '' - else - false - end - end - def report_active(task=nil) self.active = true if task!=nil diff --git a/app/views/graders/_grader_list.html.haml b/app/views/graders/_grader_list.html.haml --- a/app/views/graders/_grader_list.html.haml +++ b/app/views/graders/_grader_list.html.haml @@ -15,7 +15,7 @@ %tr{:class => c} = render :partial => 'grader', :locals => {:grader => grader} - if not grader.terminated - - if GraderProcess.grader_control_enabled? + - if GraderScript.grader_control_enabled? %td= link_to 'stop', {:action => 'stop', :id => grader} - else %td= link_to 'clear', {:action => 'clear', :id => grader} diff --git a/app/views/graders/list.html.haml b/app/views/graders/list.html.haml --- a/app/views/graders/list.html.haml +++ b/app/views/graders/list.html.haml @@ -4,8 +4,22 @@ %h1 Grader information -- form_for :clear, nil, :url => {:action => 'clear_all'} do |f| - = submit_tag 'Clear all data' +.submitbox + .item + Grader control: + .item + - form_for :clear, nil, :url => {:action => 'start_grading'} do |f| + = submit_tag 'Start graders in grading env' + .item + - form_for :clear, nil, :url => {:action => 'start_exam'} do |f| + = submit_tag 'Start graders in exam env' + .item + - form_for :clear, nil, :url => {:action => 'stop_all'} do |f| + = submit_tag 'Stop all running graders' + .item + - form_for :clear, nil, :url => {:action => 'clear_all'} do |f| + = submit_tag 'Clear all data' + %br{:style => 'clear:both'}/ - if @last_task Last task: diff --git a/lib/grader_script.rb b/lib/grader_script.rb new file mode 100644 --- /dev/null +++ b/lib/grader_script.rb @@ -0,0 +1,35 @@ +module GraderScript + + def self.grader_control_enabled? + if defined? GRADER_SCRIPT_DIR + GRADER_SCRIPT_DIR != '' + else + false + end + end + + def self.stop_grader(pid) + if GraderScript.grader_control_enabled? + cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}" + system(cmd) + end + end + + def self.stop_graders(pids) + if GraderScript.grader_control_enabled? + pid_str = (pids.map { |process| process.pid.to_a }).join ' ' + cmd = "#{GRADER_SCRIPT_DIR}/grader stop " + pid_str + system(cmd) + end + end + + def self.start_grader(env) + if GraderScript.grader_control_enabled? + cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} queue &" + system(cmd) + cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} test_request &" + system(cmd) + end + end + +end diff --git a/public/stylesheets/graders.css b/public/stylesheets/graders.css --- a/public/stylesheets/graders.css +++ b/public/stylesheets/graders.css @@ -9,4 +9,9 @@ border: 1px solid black; background: #ffcccc; text-align: center; -} \ No newline at end of file +} + +.submitbox .item { + padding-right: 5px; + float: left; +}