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
2 end
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 +
18 + end
@@ -23,28 +23,29
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
@@ -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
12 end
26 end
13
27
14 - def self.report_inactive(ip,pid,mode)
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
38 + end
39 +
40 + def report_inactive()
41 + self.active = false
42 + self.task = nil
43 + self.save
44 + end
45 +
46 + protected
47 +
48 + def self.stalled_time()
49 + return 1.minute
15 end
50 end
16
51
17 end
52 end
@@ -1,32 +1,33
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
You need to be logged in to leave comments. Login now