Description:
updated grader list page git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@375 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

r175:f0e96dfc88c2 - - 5 files changed: 50 inserted, 10 deleted

@@ -1,34 +1,42
1 1 class GradersController < ApplicationController
2 2
3 3 before_filter :admin_authorization
4 4
5 - verify :method => :post, :only => ['clear_all'],
5 + verify :method => :post, :only => ['clear_all', 'clear_terminated'],
6 6 :redirect_to => {:action => 'index'}
7 7
8 8 def index
9 9 redirect_to :action => 'list'
10 10 end
11 11
12 12 def list
13 - @grader_processes = GraderProcess.find(:all,
14 - :order => 'updated_at desc')
13 + @grader_processes = GraderProcess.find_running_graders
15 14 @stalled_processes = GraderProcess.find_stalled_process
16 15
16 + @terminated_processes = GraderProcess.find_terminated_graders
17 +
17 18 @last_task = Task.find(:first,
18 19 :order => 'created_at DESC')
19 20 @last_test_request = TestRequest.find(:first,
20 21 :order => 'created_at DESC')
21 22 end
22 23
23 24 def clear
24 25 grader_proc = GraderProcess.find(params[:id])
25 26 grader_proc.destroy if grader_proc!=nil
26 27 redirect_to :action => 'list'
27 28 end
28 29
30 + def clear_terminated
31 + GraderProcess.find_terminated_graders.each do |p|
32 + p.destroy
33 + end
34 + redirect_to :action => 'list'
35 + end
36 +
29 37 def clear_all
30 38 GraderProcess.find(:all).each do |p|
31 39 p.destroy
32 40 end
33 41 redirect_to :action => 'list'
34 42 end
@@ -12,24 +12,37
12 12 grader = GraderProcess.find_by_host_and_pid(host,pid)
13 13 if grader
14 14 grader.mode = mode
15 15 grader.active = nil
16 16 grader.task_id = nil
17 17 grader.task_type = nil
18 + grader.terminated = false
18 19 grader.save
19 20 else
20 21 grader = GraderProcess.create(:host => host,
21 22 :pid => pid,
22 - :mode => mode)
23 + :mode => mode,
24 + :terminated => false)
23 25 end
24 26 grader
25 27 end
26 28
27 - def self.find_stalled_process()
29 + def self.find_running_graders
30 + GraderProcess.find(:all,
31 + :conditions => {:terminated => 0})
32 + end
33 +
34 + def self.find_terminated_graders
28 35 GraderProcess.find(:all,
29 - :conditions => ["active AND updated_at < ?",
36 + :conditions => "`terminated`")
37 + end
38 +
39 + def self.find_stalled_process
40 + GraderProcess.find(:all,
41 + :conditions => ["(`terminated` = 0) AND active AND " +
42 + "(updated_at < ?)",
30 43 Time.now.gmtime - GraderProcess.stalled_time])
31 44 end
32 45
33 46 def report_active(task=nil)
34 47 self.active = true
35 48 if task!=nil
@@ -51,12 +64,17
51 64 self.task_id = nil
52 65 self.task_type = nil
53 66 end
54 67 self.save
55 68 end
56 69
70 + def terminate
71 + self.terminated = true
72 + self.save
73 + end
74 +
57 75 protected
58 76
59 77 def self.stalled_time()
60 78 return 1.minute
61 79 end
62 80
@@ -1,7 +1,7
1 -
1 + - if grader_list.length!=0
2 2 %table.graders
3 3 %tr
4 4 %th host
5 5 %th pid
6 6 %th mode
7 7 %th last updated
@@ -11,8 +11,14
11 11 - if grader.active
12 12 - c = 'active'
13 13 - else
14 14 - c = 'inactive'
15 15 %tr{:class => c}
16 16 = render :partial => 'grader', :locals => {:grader => grader}
17 + - if not grader.terminated
18 + %td= link_to 'stop', {:action => 'stop', :id => grader}
19 + - else
17 20 %td= link_to 'clear', {:action => 'clear', :id => grader}
21 + - else
22 + %ul
23 + %li None
18 24
@@ -15,13 +15,20
15 15
16 16 - if @last_test_request
17 17 Last test_request:
18 18 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
19 19
20 20
21 - %h3 Current graders
21 + %h2 Current graders
22 22
23 23 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
24 24
25 - %h3 Stalled graders
25 + %h2 Stalled graders
26 26
27 27 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
28 +
29 + %h2 Terminated graders
30 +
31 + - form_for :clear, nil, :url => {:action => 'clear_terminated'} do |f|
32 + = submit_tag 'Clear data for terminated graders'
33 +
34 + = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes}
@@ -6,13 +6,13
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 20090416235658) do
12 + ActiveRecord::Schema.define(:version => 20090426131044) do
13 13
14 14 create_table "announcements", :force => true do |t|
15 15 t.string "author"
16 16 t.text "body"
17 17 t.boolean "published"
18 18 t.datetime "created_at"
@@ -48,12 +48,13
48 48 t.string "mode"
49 49 t.boolean "active"
50 50 t.datetime "created_at"
51 51 t.datetime "updated_at"
52 52 t.integer "task_id"
53 53 t.string "task_type"
54 + t.boolean "terminated"
54 55 end
55 56
56 57 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
57 58
58 59 create_table "languages", :force => true do |t|
59 60 t.string "name", :limit => 10
You need to be logged in to leave comments. Login now