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:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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,11 +1,15 | |||||
|
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', |
|
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 | ||
@@ -62,21 +66,31 | |||||
|
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 |
@@ -40,20 +40,12 | |||||
|
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 |
@@ -12,13 +12,13 | |||||
|
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 Grader |
|
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 |
@@ -1,14 +1,28 | |||||
|
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/ |
@@ -6,7 +6,12 | |||||
|
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