Description:
added more grader control git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@434 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

r203:e7056be0091a - - 6 files changed: 81 inserted, 21 deleted

@@ -0,0 +1,35
1 + module GraderScript
2 +
3 + def self.grader_control_enabled?
4 + if defined? GRADER_SCRIPT_DIR
5 + GRADER_SCRIPT_DIR != ''
6 + else
7 + false
8 + end
9 + end
10 +
11 + def self.stop_grader(pid)
12 + if GraderScript.grader_control_enabled?
13 + cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}"
14 + system(cmd)
15 + end
16 + end
17 +
18 + def self.stop_graders(pids)
19 + if GraderScript.grader_control_enabled?
20 + pid_str = (pids.map { |process| process.pid.to_a }).join ' '
21 + cmd = "#{GRADER_SCRIPT_DIR}/grader stop " + pid_str
22 + system(cmd)
23 + end
24 + end
25 +
26 + def self.start_grader(env)
27 + if GraderScript.grader_control_enabled?
28 + cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} queue &"
29 + system(cmd)
30 + cmd = "#{GRADER_SCRIPT_DIR}/grader #{env} test_request &"
31 + system(cmd)
32 + end
33 + end
34 +
35 + end
@@ -2,7 +2,11
2 2
3 3 before_filter :admin_authorization
4 4
5 - verify :method => :post, :only => ['clear_all', 'clear_terminated'],
5 + verify :method => :post, :only => ['clear_all',
6 + 'start_exam',
7 + 'start_grading',
8 + 'stop_all',
9 + 'clear_terminated'],
6 10 :redirect_to => {:action => 'index'}
7 11
8 12 def index
@@ -65,18 +69,28
65 69
66 70 def stop
67 71 grader_proc = GraderProcess.find(params[:id])
68 - stop_grader(grader_proc.pid)
72 + GraderScript.stop_grader(grader_proc.pid)
73 + flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
74 + redirect_to :action => 'list'
75 + end
76 +
77 + def stop_all
78 + GraderScript.stop_graders(GraderProcess.find_running_graders +
79 + GraderProcess.find_stalled_process)
80 + flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
69 81 redirect_to :action => 'list'
70 82 end
71 83
72 -
73 - protected
84 + def start_grading
85 + GraderScript.start_grader('grading')
86 + flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
87 + redirect_to :action => 'list'
88 + end
74 89
75 - def stop_grader(pid)
76 - if GraderProcess.grader_control_enabled?
77 - cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}"
78 - system(cmd)
79 - end
90 + def start_exam
91 + GraderScript.start_grader('exam')
92 + flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
93 + redirect_to :action => 'list'
80 94 end
81 95
82 96 end
@@ -43,14 +43,6
43 43 Time.now.gmtime - GraderProcess.stalled_time])
44 44 end
45 45
46 - def self.grader_control_enabled?
47 - if defined? GRADER_SCRIPT_DIR
48 - GRADER_SCRIPT_DIR != ''
49 - else
50 - false
51 - end
52 - end
53 -
54 46 def report_active(task=nil)
55 47 self.active = true
56 48 if task!=nil
@@ -15,7 +15,7
15 15 %tr{:class => c}
16 16 = render :partial => 'grader', :locals => {:grader => grader}
17 17 - if not grader.terminated
18 - - if GraderProcess.grader_control_enabled?
18 + - if GraderScript.grader_control_enabled?
19 19 %td= link_to 'stop', {:action => 'stop', :id => grader}
20 20 - else
21 21 %td= link_to 'clear', {:action => 'clear', :id => grader}
@@ -4,8 +4,22
4 4
5 5 %h1 Grader information
6 6
7 - - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
8 - = submit_tag 'Clear all data'
7 + .submitbox
8 + .item
9 + Grader control:
10 + .item
11 + - form_for :clear, nil, :url => {:action => 'start_grading'} do |f|
12 + = submit_tag 'Start graders in grading env'
13 + .item
14 + - form_for :clear, nil, :url => {:action => 'start_exam'} do |f|
15 + = submit_tag 'Start graders in exam env'
16 + .item
17 + - form_for :clear, nil, :url => {:action => 'stop_all'} do |f|
18 + = submit_tag 'Stop all running graders'
19 + .item
20 + - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
21 + = submit_tag 'Clear all data'
22 + %br{:style => 'clear:both'}/
9 23
10 24 - if @last_task
11 25 Last task:
@@ -9,4 +9,9
9 9 border: 1px solid black;
10 10 background: #ffcccc;
11 11 text-align: center;
12 - } No newline at end of file
12 + }
13 +
14 + .submitbox .item {
15 + padding-right: 5px;
16 + float: left;
17 + }
You need to be logged in to leave comments. Login now