Show More
Commit Description:
added first grader script calls from web (to stop grader)...
Commit Description:
added first grader script calls from web (to stop grader) git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@433 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/models/grader_process.rb | 89 lines | 2.1 KiB | text/x-ruby | RubyLexer |
class GraderProcess < ActiveRecord::Base
def self.find_by_host_and_pid(host,pid)
return GraderProcess.find(:first,
:conditions => {
:host => host,
:pid => pid
})
end
def self.register(host,pid,mode)
grader = GraderProcess.find_by_host_and_pid(host,pid)
if grader
grader.mode = mode
grader.active = nil
grader.task_id = nil
grader.task_type = nil
grader.terminated = false
grader.save
else
grader = GraderProcess.create(:host => host,
:pid => pid,
:mode => mode,
:terminated => false)
end
grader
end
def self.find_running_graders
GraderProcess.find(:all,
:conditions => {:terminated => 0})
end
def self.find_terminated_graders
GraderProcess.find(:all,
:conditions => "`terminated`")
end
def self.find_stalled_process
GraderProcess.find(:all,
:conditions => ["(`terminated` = 0) AND active AND " +
"(updated_at < ?)",
Time.now.gmtime - GraderProcess.stalled_time])
end
def self.grader_control_enabled?
if defined? GRADER_SCRIPT_DIR
GRADER_SCRIPT_DIR != ''
else
false
end
end
def report_active(task=nil)
self.active = true
if task!=nil
self.task_id = task.id
self.task_type = task.class.to_s
else
self.task_id = nil
self.task_type = nil
end
self.save
end
def report_inactive(task=nil)
self.active = false
if task!=nil
self.task_id = task.id
self.task_type = task.class.to_s
else
self.task_id = nil
self.task_type = nil
end
self.save
end
def terminate
self.terminated = true
self.save
end
protected
def self.stalled_time()
return 1.minute
end
end