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
@@ -11,52 +11,53
11 end
11 end
12
12
13 def login
13 def login
14 reset_session
14 reset_session
15 render :action => 'login', :layout => 'empty'
15 render :action => 'login', :layout => 'empty'
16 end
16 end
17
17
18 def list
18 def list
19 prepare_list_information
19 prepare_list_information
20 end
20 end
21
21
22 def submit
22 def submit
23 @submission = Submission.new(params[:submission])
23 @submission = Submission.new(params[:submission])
24 @submission.user_id = session[:user_id]
24 @submission.user_id = session[:user_id]
25 @submission.language_id = 0
25 @submission.language_id = 0
26 @submission.source = params['file'].read if params['file']!=''
26 @submission.source = params['file'].read if params['file']!=''
27 @submission.submitted_at = Time.new
27 @submission.submitted_at = Time.new
28 if @submission.valid?
28 if @submission.valid?
29 if @submission.save == false
29 if @submission.save == false
30 flash[:notice] = 'Error saving your submission'
30 flash[:notice] = 'Error saving your submission'
31 elsif Task.create(:submission_id => @submission.id,
31 elsif Task.create(:submission_id => @submission.id,
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
42 submission = Submission.find(params[:id])
43 submission = Submission.find(params[:id])
43 if submission.user_id == session[:user_id]
44 if submission.user_id == session[:user_id]
44 fname = submission.problem.name + '.' + submission.language.ext
45 fname = submission.problem.name + '.' + submission.language.ext
45 send_data(submission.source,
46 send_data(submission.source,
46 {:filename => fname,
47 {:filename => fname,
47 :type => 'text/plain'})
48 :type => 'text/plain'})
48 else
49 else
49 flash[:notice] = 'Error viewing source'
50 flash[:notice] = 'Error viewing source'
50 end
51 end
51 end
52 end
52
53
53 protected
54 protected
54 def prepare_list_information
55 def prepare_list_information
55 @problems = Problem.find_available_problems
56 @problems = Problem.find_available_problems
56 @prob_submissions = Array.new
57 @prob_submissions = Array.new
57 @user = User.find(session[:user_id])
58 @user = User.find(session[:user_id])
58 @problems.each do |p|
59 @problems.each do |p|
59 c, sub = Submission.find_by_user_and_problem(@user.id,p.id)
60 c, sub = Submission.find_by_user_and_problem(@user.id,p.id)
60 @prob_submissions << [c,sub]
61 @prob_submissions << [c,sub]
61 end
62 end
62 end
63 end
@@ -1,17 +1,52
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 => {
6 :ip => ip,
8 :ip => ip,
7 :pid => pid
9 :pid => pid
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
@@ -1,44 +1,45
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 ActiveRecord to incrementally modify your database, and
2 # please use the migrations feature of ActiveRecord 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 => 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
16 t.integer "pid"
16 t.integer "pid"
17 t.string "mode"
17 t.string "mode"
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"
24
25
25 create_table "languages", :force => true do |t|
26 create_table "languages", :force => true do |t|
26 t.string "name", :limit => 10
27 t.string "name", :limit => 10
27 t.string "pretty_name"
28 t.string "pretty_name"
28 t.string "ext", :limit => 10
29 t.string "ext", :limit => 10
29 end
30 end
30
31
31 create_table "problems", :force => true do |t|
32 create_table "problems", :force => true do |t|
32 t.string "name", :limit => 30
33 t.string "name", :limit => 30
33 t.string "full_name"
34 t.string "full_name"
34 t.integer "full_score"
35 t.integer "full_score"
35 t.date "date_added"
36 t.date "date_added"
36 t.boolean "available"
37 t.boolean "available"
37 t.string "url"
38 t.string "url"
38 end
39 end
39
40
40 create_table "rights", :force => true do |t|
41 create_table "rights", :force => true do |t|
41 t.string "name"
42 t.string "name"
42 t.string "controller"
43 t.string "controller"
43 t.string "action"
44 t.string "action"
44 end
45 end
You need to be logged in to leave comments. Login now