Description:
renamed ip to host in GraderProcess git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@64 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

r34:5e680c886b7e - - 6 files changed: 35 inserted, 11 deleted

@@ -0,0 +1,9
1 + class RenameGraderProcessColumnIpToHost < ActiveRecord::Migration
2 + def self.up
3 + rename_column :grader_processes, :ip, :host
4 + end
5 +
6 + def self.down
7 + rename_column :grader_processes, :host, :ip
8 + end
9 + end
@@ -1,33 +1,33
1 class GraderProcess < ActiveRecord::Base
1 class GraderProcess < ActiveRecord::Base
2
2
3 belongs_to :task
3 belongs_to :task
4
4
5 - def self.find_by_ip_and_pid(ip,pid)
5 + def self.find_by_host_and_pid(host,pid)
6 return GraderProcess.find(:first,
6 return GraderProcess.find(:first,
7 :conditions => {
7 :conditions => {
8 - :ip => ip,
8 + :host => host,
9 :pid => pid
9 :pid => pid
10 })
10 })
11 end
11 end
12 -
12 +
13 - def self.register(ip,pid,mode)
13 + def self.register(host,pid,mode)
14 - grader = GraderProcess.find_by_ip_and_pid(ip,pid)
14 + grader = GraderProcess.find_by_host_and_pid(host,pid)
15 if grader
15 if grader
16 grader.mode = mode
16 grader.mode = mode
17 grader.active = nil
17 grader.active = nil
18 grader.task_id = nil
18 grader.task_id = nil
19 grader.save
19 grader.save
20 else
20 else
21 - grader = GraderProcess.create(:ip => ip,
21 + grader = GraderProcess.create(:host => host,
22 :pid => pid,
22 :pid => pid,
23 :mode => mode)
23 :mode => mode)
24 end
24 end
25 grader
25 grader
26 end
26 end
27
27
28 def self.find_stalled_process()
28 def self.find_stalled_process()
29 GraderProcess.find(:all,
29 GraderProcess.find(:all,
30 :conditions => ["active AND updated_at < ?",
30 :conditions => ["active AND updated_at < ?",
31 Time.now.gmtime - GraderProcess.stalled_time])
31 Time.now.gmtime - GraderProcess.stalled_time])
32 end
32 end
33
33
@@ -1,30 +1,45
1 class Task < ActiveRecord::Base
1 class Task < ActiveRecord::Base
2
2
3 STATUS_GRADING = 0
3 STATUS_GRADING = 0
4 STATUS_INQUEUE = 1
4 STATUS_INQUEUE = 1
5 STATUS_COMPLETE = 2
5 STATUS_COMPLETE = 2
6
6
7 def status_inqueue
7 def status_inqueue
8 self.status = Task::STATUS_INQUEUE
8 self.status = Task::STATUS_INQUEUE
9 end
9 end
10
10
11 + def status_inqueue!
12 + status_inqueue
13 + self.save
14 + end
15 +
11 def status_grading
16 def status_grading
12 self.status = Task::STATUS_GRADING
17 self.status = Task::STATUS_GRADING
13 end
18 end
14
19
20 + def status_grading!
21 + status_grading
22 + self.save
23 + end
24 +
15 def status_complete
25 def status_complete
16 self.status = Task::STATUS_COMPLETE
26 self.status = Task::STATUS_COMPLETE
17 end
27 end
18
28
29 + def status_complete!
30 + status_complete
31 + self.save
32 + end
33 +
19 def self.get_inqueue_and_change_status(status)
34 def self.get_inqueue_and_change_status(status)
20 task = nil
35 task = nil
21 begin
36 begin
22 Task.transaction do
37 Task.transaction do
23 task = Task.find(:first,
38 task = Task.find(:first,
24 :order => "created_at",
39 :order => "created_at",
25 :conditions => {:status=> Task::STATUS_INQUEUE},
40 :conditions => {:status=> Task::STATUS_INQUEUE},
26 :lock => true)
41 :lock => true)
27 if task!=nil
42 if task!=nil
28 task.status = status
43 task.status = status
29 task.save!
44 task.save!
30 end
45 end
@@ -1,9 +1,9
1
1
2 - %td= grader.ip
2 + %td= grader.host
3 %td= grader.pid
3 %td= grader.pid
4 %td= grader.updated_at.strftime("%H:%M:%S") if grader.updated_at!=nil
4 %td= grader.updated_at.strftime("%H:%M:%S") if grader.updated_at!=nil
5 %td
5 %td
6 - if grader.task_id==nil
6 - if grader.task_id==nil
7 \-
7 \-
8 - else
8 - else
9 = grader.task_id
9 = grader.task_id
@@ -1,16 +1,16
1
1
2 %table.graders
2 %table.graders
3 %tr
3 %tr
4 - %th ip
4 + %th host
5 %th pid
5 %th pid
6 %th last updated
6 %th last updated
7 %th task
7 %th task
8 - grader_list.each do |grader|
8 - grader_list.each do |grader|
9 - if grader.active
9 - if grader.active
10 - c = 'active'
10 - c = 'active'
11 - else
11 - else
12 - c = 'inactive'
12 - c = 'inactive'
13 %tr{:class => c}
13 %tr{:class => c}
14 = render :partial => 'grader', :locals => {:grader => grader}
14 = render :partial => 'grader', :locals => {:grader => grader}
15 %td= link_to 'clear', {:action => 'clear', :id => grader}
15 %td= link_to 'clear', {:action => 'clear', :id => grader}
16
16
@@ -1,36 +1,36
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 => 16) do
12 + ActiveRecord::Schema.define(:version => 17) 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 "host", :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 t.integer "task_id"
22 end
22 end
23
23
24 - add_index "grader_processes", ["ip", "pid"], :name => "index_grader_processes_on_ip_and_pid"
24 + add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
25
25
26 create_table "languages", :force => true do |t|
26 create_table "languages", :force => true do |t|
27 t.string "name", :limit => 10
27 t.string "name", :limit => 10
28 t.string "pretty_name"
28 t.string "pretty_name"
29 t.string "ext", :limit => 10
29 t.string "ext", :limit => 10
30 end
30 end
31
31
32 create_table "problems", :force => true do |t|
32 create_table "problems", :force => true do |t|
33 t.string "name", :limit => 30
33 t.string "name", :limit => 30
34 t.string "full_name"
34 t.string "full_name"
35 t.integer "full_score"
35 t.integer "full_score"
36 t.date "date_added"
36 t.date "date_added"
You need to be logged in to leave comments. Login now