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
@@ -1,29 +1,33
1 class GradersController < ApplicationController
1 class GradersController < ApplicationController
2
2
3 before_filter :admin_authorization
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 :redirect_to => {:action => 'index'}
10 :redirect_to => {:action => 'index'}
7
11
8 def index
12 def index
9 redirect_to :action => 'list'
13 redirect_to :action => 'list'
10 end
14 end
11
15
12 def list
16 def list
13 @grader_processes = GraderProcess.find_running_graders
17 @grader_processes = GraderProcess.find_running_graders
14 @stalled_processes = GraderProcess.find_stalled_process
18 @stalled_processes = GraderProcess.find_stalled_process
15
19
16 @terminated_processes = GraderProcess.find_terminated_graders
20 @terminated_processes = GraderProcess.find_terminated_graders
17
21
18 @last_task = Task.find(:first,
22 @last_task = Task.find(:first,
19 :order => 'created_at DESC')
23 :order => 'created_at DESC')
20 @last_test_request = TestRequest.find(:first,
24 @last_test_request = TestRequest.find(:first,
21 :order => 'created_at DESC')
25 :order => 'created_at DESC')
22 end
26 end
23
27
24 def clear
28 def clear
25 grader_proc = GraderProcess.find(params[:id])
29 grader_proc = GraderProcess.find(params[:id])
26 grader_proc.destroy if grader_proc!=nil
30 grader_proc.destroy if grader_proc!=nil
27 redirect_to :action => 'list'
31 redirect_to :action => 'list'
28 end
32 end
29
33
@@ -44,39 +48,49
44 def view
48 def view
45 if params[:type]=='Task'
49 if params[:type]=='Task'
46 redirect_to :action => 'task', :id => params[:id]
50 redirect_to :action => 'task', :id => params[:id]
47 else
51 else
48 redirect_to :action => 'test_request', :id => params[:id]
52 redirect_to :action => 'test_request', :id => params[:id]
49 end
53 end
50 end
54 end
51
55
52 def test_request
56 def test_request
53 @test_request = TestRequest.find(params[:id])
57 @test_request = TestRequest.find(params[:id])
54 end
58 end
55
59
56 def task
60 def task
57 @task = Task.find(params[:id])
61 @task = Task.find(params[:id])
58 end
62 end
59
63
60 def submission
64 def submission
61 @submission = Submission.find(params[:id])
65 @submission = Submission.find(params[:id])
62 end
66 end
63
67
64 # various grader controls
68 # various grader controls
65
69
66 def stop
70 def stop
67 grader_proc = GraderProcess.find(params[:id])
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 redirect_to :action => 'list'
81 redirect_to :action => 'list'
70 end
82 end
71
83
72 -
84 + def start_grading
73 - protected
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)
90 + def start_exam
76 - if GraderProcess.grader_control_enabled?
91 + GraderScript.start_grader('exam')
77 - cmd = "#{GRADER_SCRIPT_DIR}/grader stop #{pid}"
92 + flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
78 - system(cmd)
93 + redirect_to :action => 'list'
79 - end
80 end
94 end
81
95
82 end
96 end
@@ -22,56 +22,48
22 :pid => pid,
22 :pid => pid,
23 :mode => mode,
23 :mode => mode,
24 :terminated => false)
24 :terminated => false)
25 end
25 end
26 grader
26 grader
27 end
27 end
28
28
29 def self.find_running_graders
29 def self.find_running_graders
30 GraderProcess.find(:all,
30 GraderProcess.find(:all,
31 :conditions => {:terminated => 0})
31 :conditions => {:terminated => 0})
32 end
32 end
33
33
34 def self.find_terminated_graders
34 def self.find_terminated_graders
35 GraderProcess.find(:all,
35 GraderProcess.find(:all,
36 :conditions => "`terminated`")
36 :conditions => "`terminated`")
37 end
37 end
38
38
39 def self.find_stalled_process
39 def self.find_stalled_process
40 GraderProcess.find(:all,
40 GraderProcess.find(:all,
41 :conditions => ["(`terminated` = 0) AND active AND " +
41 :conditions => ["(`terminated` = 0) AND active AND " +
42 "(updated_at < ?)",
42 "(updated_at < ?)",
43 Time.now.gmtime - GraderProcess.stalled_time])
43 Time.now.gmtime - GraderProcess.stalled_time])
44 end
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 def report_active(task=nil)
46 def report_active(task=nil)
55 self.active = true
47 self.active = true
56 if task!=nil
48 if task!=nil
57 self.task_id = task.id
49 self.task_id = task.id
58 self.task_type = task.class.to_s
50 self.task_type = task.class.to_s
59 else
51 else
60 self.task_id = nil
52 self.task_id = nil
61 self.task_type = nil
53 self.task_type = nil
62 end
54 end
63 self.save
55 self.save
64 end
56 end
65
57
66 def report_inactive(task=nil)
58 def report_inactive(task=nil)
67 self.active = false
59 self.active = false
68 if task!=nil
60 if task!=nil
69 self.task_id = task.id
61 self.task_id = task.id
70 self.task_type = task.class.to_s
62 self.task_type = task.class.to_s
71 else
63 else
72 self.task_id = nil
64 self.task_id = nil
73 self.task_type = nil
65 self.task_type = nil
74 end
66 end
75 self.save
67 self.save
76 end
68 end
77
69
@@ -1,25 +1,25
1 - if grader_list.length!=0
1 - if grader_list.length!=0
2 %table.graders
2 %table.graders
3 %tr
3 %tr
4 %th host
4 %th host
5 %th pid
5 %th pid
6 %th mode
6 %th mode
7 %th last updated
7 %th last updated
8 %th type
8 %th type
9 %th task
9 %th task
10 - grader_list.each do |grader|
10 - grader_list.each do |grader|
11 - if grader.active
11 - if grader.active
12 - c = 'active'
12 - c = 'active'
13 - else
13 - else
14 - c = 'inactive'
14 - c = 'inactive'
15 %tr{:class => c}
15 %tr{:class => c}
16 = render :partial => 'grader', :locals => {:grader => grader}
16 = render :partial => 'grader', :locals => {:grader => grader}
17 - if not grader.terminated
17 - if not grader.terminated
18 - - if GraderProcess.grader_control_enabled?
18 + - if GraderScript.grader_control_enabled?
19 %td= link_to 'stop', {:action => 'stop', :id => grader}
19 %td= link_to 'stop', {:action => 'stop', :id => grader}
20 - else
20 - else
21 %td= link_to 'clear', {:action => 'clear', :id => grader}
21 %td= link_to 'clear', {:action => 'clear', :id => grader}
22 - else
22 - else
23 %ul
23 %ul
24 %li None
24 %li None
25
25
@@ -1,32 +1,46
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'graders'
2 = stylesheet_link_tag 'graders'
3 <meta http-equiv ="refresh" content="60"/>
3 <meta http-equiv ="refresh" content="60"/>
4
4
5 %h1 Grader information
5 %h1 Grader information
6
6
7 - - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
7 + .submitbox
8 - = submit_tag 'Clear all data'
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 - if @last_task
24 - if @last_task
11 Last task:
25 Last task:
12 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
26 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
13
27
14 %br/
28 %br/
15
29
16 - if @last_test_request
30 - if @last_test_request
17 Last test_request:
31 Last test_request:
18 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
32 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
19
33
20
34
21 %h2 Current graders
35 %h2 Current graders
22
36
23 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
37 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
24
38
25 %h2 Stalled graders
39 %h2 Stalled graders
26
40
27 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
41 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
28
42
29 %h2 Terminated graders
43 %h2 Terminated graders
30
44
31 - form_for :clear, nil, :url => {:action => 'clear_terminated'} do |f|
45 - form_for :clear, nil, :url => {:action => 'clear_terminated'} do |f|
32 = submit_tag 'Clear data for terminated graders'
46 = submit_tag 'Clear data for terminated graders'
@@ -1,12 +1,17
1
1
2 table.graders tr.active {
2 table.graders tr.active {
3 border: 1px solid black;
3 border: 1px solid black;
4 background: lightgreen;
4 background: lightgreen;
5 text-align: center;
5 text-align: center;
6 }
6 }
7
7
8 table.graders tr.inactive {
8 table.graders tr.inactive {
9 border: 1px solid black;
9 border: 1px solid black;
10 background: #ffcccc;
10 background: #ffcccc;
11 text-align: center;
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