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 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 18 end
@@ -29,16 +29,17
29 29 if @submission.save == false
30 30 flash[:notice] = 'Error saving your submission'
31 31 elsif Task.create(:submission_id => @submission.id,
32 32 :status => Task::STATUS_INQUEUE) == false
33 33 flash[:notice] = 'Error adding your submission to task queue'
34 34 end
35 + else
36 + prepare_list_information
37 + render :action => 'list' and return
35 38 end
36 -
37 - prepare_list_information
38 - render :action => 'list'
39 + redirect_to :action => 'list'
39 40 end
40 41
41 42 def get_source
42 43 submission = Submission.find(params[:id])
43 44 if submission.user_id == session[:user_id]
44 45 fname = submission.problem.name + '.' + submission.language.ext
@@ -1,17 +1,52
1 1 class GraderProcess < ActiveRecord::Base
2 2
3 + belongs_to :task
4 +
3 5 def self.find_by_ip_and_pid(ip,pid)
4 6 return GraderProcess.find(:first,
5 7 :conditions => {
6 8 :ip => ip,
7 9 :pid => pid
8 10 })
9 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 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 44 end
16 45
46 + protected
47 +
48 + def self.stalled_time()
49 + return 1.minute
50 + end
51 +
17 52 end
@@ -6,21 +6,22
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 => 15) do
12 + ActiveRecord::Schema.define(:version => 16) do
13 13
14 14 create_table "grader_processes", :force => true do |t|
15 15 t.string "ip", :limit => 20
16 16 t.integer "pid"
17 17 t.string "mode"
18 18 t.boolean "active"
19 19 t.datetime "created_at"
20 20 t.datetime "updated_at"
21 + t.integer "task_id"
21 22 end
22 23
23 24 add_index "grader_processes", ["ip", "pid"], :name => "index_grader_processes_on_ip_and_pid"
24 25
25 26 create_table "languages", :force => true do |t|
26 27 t.string "name", :limit => 10
You need to be logged in to leave comments. Login now