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: 66 inserted, 26 deleted

@@ -1,52 +1,60
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', 'clear_terminated'],
6 :redirect_to => {:action => 'index'}
6 :redirect_to => {:action => 'index'}
7
7
8 def index
8 def index
9 redirect_to :action => 'list'
9 redirect_to :action => 'list'
10 end
10 end
11
11
12 def list
12 def list
13 - @grader_processes = GraderProcess.find(:all,
13 + @grader_processes = GraderProcess.find_running_graders
14 - :order => 'updated_at desc')
15 @stalled_processes = GraderProcess.find_stalled_process
14 @stalled_processes = GraderProcess.find_stalled_process
15 +
16 + @terminated_processes = GraderProcess.find_terminated_graders
16
17
17 @last_task = Task.find(:first,
18 @last_task = Task.find(:first,
18 :order => 'created_at DESC')
19 :order => 'created_at DESC')
19 @last_test_request = TestRequest.find(:first,
20 @last_test_request = TestRequest.find(:first,
20 :order => 'created_at DESC')
21 :order => 'created_at DESC')
21 end
22 end
22
23
23 def clear
24 def clear
24 grader_proc = GraderProcess.find(params[:id])
25 grader_proc = GraderProcess.find(params[:id])
25 grader_proc.destroy if grader_proc!=nil
26 grader_proc.destroy if grader_proc!=nil
26 redirect_to :action => 'list'
27 redirect_to :action => 'list'
27 end
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 def clear_all
37 def clear_all
30 GraderProcess.find(:all).each do |p|
38 GraderProcess.find(:all).each do |p|
31 p.destroy
39 p.destroy
32 end
40 end
33 redirect_to :action => 'list'
41 redirect_to :action => 'list'
34 end
42 end
35
43
36 def view
44 def view
37 if params[:type]=='Task'
45 if params[:type]=='Task'
38 redirect_to :action => 'task', :id => params[:id]
46 redirect_to :action => 'task', :id => params[:id]
39 else
47 else
40 redirect_to :action => 'test_request', :id => params[:id]
48 redirect_to :action => 'test_request', :id => params[:id]
41 end
49 end
42 end
50 end
43
51
44 def test_request
52 def test_request
45 @test_request = TestRequest.find(params[:id])
53 @test_request = TestRequest.find(params[:id])
46 end
54 end
47
55
48 def task
56 def task
49 @task = Task.find(params[:id])
57 @task = Task.find(params[:id])
50 end
58 end
51
59
52 def submission
60 def submission
@@ -1,63 +1,81
1 class GraderProcess < ActiveRecord::Base
1 class GraderProcess < ActiveRecord::Base
2
2
3 def self.find_by_host_and_pid(host,pid)
3 def self.find_by_host_and_pid(host,pid)
4 return GraderProcess.find(:first,
4 return GraderProcess.find(:first,
5 :conditions => {
5 :conditions => {
6 :host => host,
6 :host => host,
7 :pid => pid
7 :pid => pid
8 })
8 })
9 end
9 end
10
10
11 def self.register(host,pid,mode)
11 def self.register(host,pid,mode)
12 grader = GraderProcess.find_by_host_and_pid(host,pid)
12 grader = GraderProcess.find_by_host_and_pid(host,pid)
13 if grader
13 if grader
14 grader.mode = mode
14 grader.mode = mode
15 grader.active = nil
15 grader.active = nil
16 grader.task_id = nil
16 grader.task_id = nil
17 grader.task_type = nil
17 grader.task_type = nil
18 + grader.terminated = false
18 grader.save
19 grader.save
19 else
20 else
20 grader = GraderProcess.create(:host => host,
21 grader = GraderProcess.create(:host => host,
21 :pid => pid,
22 :pid => pid,
22 - :mode => mode)
23 + :mode => mode,
24 + :terminated => false)
23 end
25 end
24 grader
26 grader
25 end
27 end
28 +
29 + def self.find_running_graders
30 + GraderProcess.find(:all,
31 + :conditions => {:terminated => 0})
32 + end
26
33
27 - def self.find_stalled_process()
34 + def self.find_terminated_graders
28 GraderProcess.find(:all,
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 Time.now.gmtime - GraderProcess.stalled_time])
43 Time.now.gmtime - GraderProcess.stalled_time])
31 end
44 end
32
45
33 def report_active(task=nil)
46 def report_active(task=nil)
34 self.active = true
47 self.active = true
35 if task!=nil
48 if task!=nil
36 self.task_id = task.id
49 self.task_id = task.id
37 self.task_type = task.class.to_s
50 self.task_type = task.class.to_s
38 else
51 else
39 self.task_id = nil
52 self.task_id = nil
40 self.task_type = nil
53 self.task_type = nil
41 end
54 end
42 self.save
55 self.save
43 end
56 end
44
57
45 def report_inactive(task=nil)
58 def report_inactive(task=nil)
46 self.active = false
59 self.active = false
47 if task!=nil
60 if task!=nil
48 self.task_id = task.id
61 self.task_id = task.id
49 self.task_type = task.class.to_s
62 self.task_type = task.class.to_s
50 else
63 else
51 self.task_id = nil
64 self.task_id = nil
52 self.task_type = nil
65 self.task_type = nil
53 end
66 end
54 self.save
67 self.save
55 end
68 end
56
69
70 + def terminate
71 + self.terminated = true
72 + self.save
73 + end
74 +
57 protected
75 protected
58
76
59 def self.stalled_time()
77 def self.stalled_time()
60 return 1.minute
78 return 1.minute
61 end
79 end
62
80
63 end
81 end
@@ -1,18 +1,24
1 + - if grader_list.length!=0
2 + %table.graders
3 + %tr
4 + %th host
5 + %th pid
6 + %th mode
7 + %th last updated
8 + %th type
9 + %th task
10 + - grader_list.each do |grader|
11 + - if grader.active
12 + - c = 'active'
13 + - else
14 + - c = 'inactive'
15 + %tr{:class => c}
16 + = render :partial => 'grader', :locals => {:grader => grader}
17 + - if not grader.terminated
18 + %td= link_to 'stop', {:action => 'stop', :id => grader}
19 + - else
20 + %td= link_to 'clear', {:action => 'clear', :id => grader}
21 + - else
22 + %ul
23 + %li None
1
24
2 - %table.graders
3 - %tr
4 - %th host
5 - %th pid
6 - %th mode
7 - %th last updated
8 - %th type
9 - %th task
10 - - grader_list.each do |grader|
11 - - if grader.active
12 - - c = 'active'
13 - - else
14 - - c = 'inactive'
15 - %tr{:class => c}
16 - = render :partial => 'grader', :locals => {:grader => grader}
17 - %td= link_to 'clear', {:action => 'clear', :id => grader}
18 -
@@ -1,27 +1,34
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="10"/>
3 <meta http-equiv ="refresh" content="10"/>
4
4
5 %h1 Grader information
5 %h1 Grader information
6
6
7 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
7 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
8 = submit_tag 'Clear all data'
8 = submit_tag 'Clear all data'
9
9
10 - if @last_task
10 - if @last_task
11 Last task:
11 Last task:
12 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
12 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
13
13
14 %br/
14 %br/
15
15
16 - if @last_test_request
16 - if @last_test_request
17 Last test_request:
17 Last test_request:
18 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
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 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
23 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
24
24
25 - %h3 Stalled graders
25 + %h2 Stalled graders
26
26
27 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
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}
@@ -1,77 +1,78
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 # please use the migrations feature of Active Record to incrementally modify your database, and
2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 # then regenerate this schema definition.
3 # then regenerate this schema definition.
4 #
4 #
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 # to create the application database on another system, you should be using db:schema:load, not running
6 # to create the application database on another system, you should be using db:schema:load, not running
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 #
9 #
10 # It's strongly recommended to check this file into your version control system.
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 create_table "announcements", :force => true do |t|
14 create_table "announcements", :force => true do |t|
15 t.string "author"
15 t.string "author"
16 t.text "body"
16 t.text "body"
17 t.boolean "published"
17 t.boolean "published"
18 t.datetime "created_at"
18 t.datetime "created_at"
19 t.datetime "updated_at"
19 t.datetime "updated_at"
20 t.boolean "frontpage", :default => false
20 t.boolean "frontpage", :default => false
21 t.boolean "contest_only", :default => false
21 t.boolean "contest_only", :default => false
22 end
22 end
23
23
24 create_table "configurations", :force => true do |t|
24 create_table "configurations", :force => true do |t|
25 t.string "key"
25 t.string "key"
26 t.string "value_type"
26 t.string "value_type"
27 t.string "value"
27 t.string "value"
28 t.datetime "created_at"
28 t.datetime "created_at"
29 t.datetime "updated_at"
29 t.datetime "updated_at"
30 end
30 end
31
31
32 create_table "countries", :force => true do |t|
32 create_table "countries", :force => true do |t|
33 t.string "name"
33 t.string "name"
34 t.datetime "created_at"
34 t.datetime "created_at"
35 t.datetime "updated_at"
35 t.datetime "updated_at"
36 end
36 end
37
37
38 create_table "descriptions", :force => true do |t|
38 create_table "descriptions", :force => true do |t|
39 t.text "body"
39 t.text "body"
40 t.boolean "markdowned"
40 t.boolean "markdowned"
41 t.datetime "created_at"
41 t.datetime "created_at"
42 t.datetime "updated_at"
42 t.datetime "updated_at"
43 end
43 end
44
44
45 create_table "grader_processes", :force => true do |t|
45 create_table "grader_processes", :force => true do |t|
46 t.string "host", :limit => 20
46 t.string "host", :limit => 20
47 t.integer "pid"
47 t.integer "pid"
48 t.string "mode"
48 t.string "mode"
49 t.boolean "active"
49 t.boolean "active"
50 t.datetime "created_at"
50 t.datetime "created_at"
51 t.datetime "updated_at"
51 t.datetime "updated_at"
52 t.integer "task_id"
52 t.integer "task_id"
53 t.string "task_type"
53 t.string "task_type"
54 + t.boolean "terminated"
54 end
55 end
55
56
56 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
57 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
57
58
58 create_table "languages", :force => true do |t|
59 create_table "languages", :force => true do |t|
59 t.string "name", :limit => 10
60 t.string "name", :limit => 10
60 t.string "pretty_name"
61 t.string "pretty_name"
61 t.string "ext", :limit => 10
62 t.string "ext", :limit => 10
62 t.string "common_ext"
63 t.string "common_ext"
63 end
64 end
64
65
65 create_table "messages", :force => true do |t|
66 create_table "messages", :force => true do |t|
66 t.integer "sender_id"
67 t.integer "sender_id"
67 t.integer "receiver_id"
68 t.integer "receiver_id"
68 t.integer "replying_message_id"
69 t.integer "replying_message_id"
69 t.text "body"
70 t.text "body"
70 t.boolean "replied"
71 t.boolean "replied"
71 t.datetime "created_at"
72 t.datetime "created_at"
72 t.datetime "updated_at"
73 t.datetime "updated_at"
73 end
74 end
74
75
75 create_table "problems", :force => true do |t|
76 create_table "problems", :force => true do |t|
76 t.string "name", :limit => 30
77 t.string "name", :limit => 30
77 t.string "full_name"
78 t.string "full_name"
You need to be logged in to leave comments. Login now