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

r32:b72d6a6d5e32 - - 9 files changed: 115 inserted, 6 deleted

@@ -0,0 +1,9
1 +
2 + %td= grader.ip
3 + %td= grader.pid
4 + %td= grader.updated_at.strftime("%H:%M:%S") if grader.updated_at!=nil
5 + %td
6 + - if grader.task_id==nil
7 + \-
8 + - else
9 + = grader.task_id
@@ -0,0 +1,16
1 +
2 + %table.graders
3 + %tr
4 + %th ip
5 + %th pid
6 + %th last updated
7 + %th task
8 + - grader_list.each do |grader|
9 + - if grader.active
10 + - c = 'active'
11 + - else
12 + - c = 'inactive'
13 + %tr{:class => c}
14 + = render :partial => 'grader', :locals => {:grader => grader}
15 + %td= link_to 'clear', {:action => 'clear', :id => grader}
16 +
@@ -0,0 +1,10
1 + - content_for :head do
2 + = stylesheet_link_tag 'graders'
3 +
4 + %h3 Current graders
5 +
6 + = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
7 +
8 + %h3 Stalled graders
9 +
10 + = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
@@ -0,0 +1,9
1 + class AddTaskToGraderProcess < ActiveRecord::Migration
2 + def self.up
3 + add_column :grader_processes, :task_id, :integer
4 + end
5 +
6 + def self.down
7 + remove_column :grader_processes, :task_id, :integer
8 + end
9 + end
@@ -0,0 +1,12
1 +
2 + table.graders tr.active {
3 + border: 1px solid black;
4 + background: lightgreen;
5 + text-align: center;
6 + }
7 +
8 + table.graders tr.inactive {
9 + border: 1px solid black;
10 + background: #ffcccc;
11 + text-align: center;
12 + } No newline at end of file
@@ -1,2 +1,18
1 class GradersController < ApplicationController
1 class GradersController < ApplicationController
2 +
3 +
4 + before_filter :authenticate
5 +
6 + def list
7 + @grader_processes = GraderProcess.find(:all,
8 + :order => 'updated_at desc')
9 + @stalled_processes = GraderProcess.find_stalled_process
10 + end
11 +
12 + def clear
13 + grader_proc = GraderProcess.find(params[:id])
14 + grader_proc.destroy if grader_proc!=nil
15 + redirect_to :action => 'list'
16 + end
17 +
2 end
18 end
@@ -32,10 +32,11
32 :status => Task::STATUS_INQUEUE) == false
32 :status => Task::STATUS_INQUEUE) == false
33 flash[:notice] = 'Error adding your submission to task queue'
33 flash[:notice] = 'Error adding your submission to task queue'
34 end
34 end
35 + else
36 + prepare_list_information
37 + render :action => 'list' and return
35 end
38 end
36 -
39 + redirect_to :action => 'list'
37 - prepare_list_information
38 - render :action => 'list'
39 end
40 end
40
41
41 def get_source
42 def get_source
@@ -1,5 +1,7
1 class GraderProcess < ActiveRecord::Base
1 class GraderProcess < ActiveRecord::Base
2
2
3 + belongs_to :task
4 +
3 def self.find_by_ip_and_pid(ip,pid)
5 def self.find_by_ip_and_pid(ip,pid)
4 return GraderProcess.find(:first,
6 return GraderProcess.find(:first,
5 :conditions => {
7 :conditions => {
@@ -8,10 +10,43
8 })
10 })
9 end
11 end
10
12
11 - def self.report_active(ip,pid,mode)
13 + def self.register(ip,pid,mode)
14 + grader = GraderProcess.find_by_ip_and_pid(ip,pid)
15 + if grader
16 + grader.mode = mode
17 + grader.active = nil
18 + grader.task_id = nil
19 + grader.save
20 + else
21 + grader = GraderProcess.create(:ip => ip,
22 + :pid => pid,
23 + :mode => mode)
24 + end
25 + grader
26 + end
27 +
28 + def self.find_stalled_process()
29 + GraderProcess.find(:all,
30 + :conditions => ["active AND updated_at < ?",
31 + Time.now.gmtime - GraderProcess.stalled_time])
32 + end
33 +
34 + def report_active(task=nil)
35 + self.active = true
36 + self.task = task
37 + self.save
12 end
38 end
13
39
14 - def self.report_inactive(ip,pid,mode)
40 + def report_inactive()
41 + self.active = false
42 + self.task = nil
43 + self.save
15 end
44 end
16
45
46 + protected
47 +
48 + def self.stalled_time()
49 + return 1.minute
50 + end
51 +
17 end
52 end
@@ -9,7 +9,7
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 => 15) do
12 + ActiveRecord::Schema.define(:version => 16) do
13
13
14 create_table "grader_processes", :force => true do |t|
14 create_table "grader_processes", :force => true do |t|
15 t.string "ip", :limit => 20
15 t.string "ip", :limit => 20
@@ -18,6 +18,7
18 t.boolean "active"
18 t.boolean "active"
19 t.datetime "created_at"
19 t.datetime "created_at"
20 t.datetime "updated_at"
20 t.datetime "updated_at"
21 + t.integer "task_id"
21 end
22 end
22
23
23 add_index "grader_processes", ["ip", "pid"], :name => "index_grader_processes_on_ip_and_pid"
24 add_index "grader_processes", ["ip", "pid"], :name => "index_grader_processes_on_ip_and_pid"
You need to be logged in to leave comments. Login now