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,40 +1,48
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
15 +
16 + @terminated_processes = GraderProcess.find_terminated_graders
16 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
35 43
36 44 def view
37 45 if params[:type]=='Task'
38 46 redirect_to :action => 'task', :id => params[:id]
39 47 else
40 48 redirect_to :action => 'test_request', :id => params[:id]
@@ -6,36 +6,49
6 6 :host => host,
7 7 :pid => pid
8 8 })
9 9 end
10 10
11 11 def self.register(host,pid,mode)
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
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 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
36 49 self.task_id = task.id
37 50 self.task_type = task.class.to_s
38 51 else
39 52 self.task_id = nil
40 53 self.task_type = nil
41 54 end
@@ -45,19 +58,24
45 58 def report_inactive(task=nil)
46 59 self.active = false
47 60 if task!=nil
48 61 self.task_id = task.id
49 62 self.task_type = task.class.to_s
50 63 else
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
63 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 -
@@ -9,19 +9,26
9 9
10 10 - if @last_task
11 11 Last task:
12 12 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
13 13
14 14 %br/
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}
@@ -1,24 +1,24
1 1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 2 # please use the migrations feature of Active Record to incrementally modify your database, and
3 3 # then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
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"
19 19 t.datetime "updated_at"
20 20 t.boolean "frontpage", :default => false
21 21 t.boolean "contest_only", :default => false
22 22 end
23 23
24 24 create_table "configurations", :force => true do |t|
@@ -42,24 +42,25
42 42 t.datetime "updated_at"
43 43 end
44 44
45 45 create_table "grader_processes", :force => true do |t|
46 46 t.string "host", :limit => 20
47 47 t.integer "pid"
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
60 61 t.string "pretty_name"
61 62 t.string "ext", :limit => 10
62 63 t.string "common_ext"
63 64 end
64 65
65 66 create_table "messages", :force => true do |t|
You need to be logged in to leave comments. Login now