# HG changeset patch # User jittat # Date 2009-11-26 05:46:09 # Node ID 75463b4f3803a38564cfa995c0a4534d4dda7b32 # Parent ac6aa35270dab3f466cd2d1851e57a953a966909 added first grader script calls from web (to stop grader) git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@433 6386c4cd-e34a-4fa8-8920-d93eb39b512e 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 @@ -61,4 +61,22 @@ @submission = Submission.find(params[:id]) end + # various grader controls + + def stop + grader_proc = GraderProcess.find(params[:id]) + stop_grader(grader_proc.pid) + redirect_to :action => 'list' + end + + + protected + + def stop_grader(pid) + if GraderProcess.grader_control_enabled? + cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}" + system(cmd) + end + 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,6 +43,14 @@ 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,8 @@ %tr{:class => c} = render :partial => 'grader', :locals => {:grader => grader} - if not grader.terminated - %td= link_to 'stop', {:action => 'stop', :id => grader} + - if GraderProcess.grader_control_enabled? + %td= link_to 'stop', {:action => 'stop', :id => grader} - else %td= link_to 'clear', {:action => 'clear', :id => grader} - else 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 @@ -1,6 +1,6 @@ - content_for :head do = stylesheet_link_tag 'graders' - + %h1 Grader information diff --git a/config/environment.rb.SAMPLE b/config/environment.rb.SAMPLE --- a/config/environment.rb.SAMPLE +++ b/config/environment.rb.SAMPLE @@ -73,6 +73,10 @@ # Include your application configuration below +# If you want to manage graders through web interface, set the path to +# script directory below +GRADER_SCRIPT_DIR = '' + # These are where inputs and outputs of test requests are stored TEST_REQUEST_INPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/input' TEST_REQUEST_OUTPUT_FILE_DIR = RAILS_ROOT + '/data/test_request/output'