Show More
Commit Description:
- clean up link to problem stat and user stat...
Commit Description:
- clean up link to problem stat and user stat
(grafted from 45d1e12e9794a23a5431222fe2f4c7461d73a529)
References:
File last commit:
Show/Diff file:
Action:
app/models/task.rb
| 68 lines
| 1.1 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | class Task < ActiveRecord::Base | ||
|
r30 | |||
|
r105 | belongs_to :submission | ||
|
r30 | STATUS_GRADING = 0 | ||
STATUS_INQUEUE = 1 | ||||
STATUS_COMPLETE = 2 | ||||
def status_inqueue | ||||
self.status = Task::STATUS_INQUEUE | ||||
end | ||||
|
r34 | def status_inqueue! | ||
status_inqueue | ||||
self.save | ||||
end | ||||
|
r30 | def status_grading | ||
self.status = Task::STATUS_GRADING | ||||
end | ||||
|
r34 | def status_grading! | ||
status_grading | ||||
self.save | ||||
end | ||||
|
r30 | def status_complete | ||
self.status = Task::STATUS_COMPLETE | ||||
end | ||||
|
r34 | def status_complete! | ||
status_complete | ||||
self.save | ||||
end | ||||
|
r36 | def status_str | ||
case self.status | ||||
when Task::STATUS_INQUEUE | ||||
"inqueue" | ||||
when Task::STATUS_GRADING | ||||
"grading" | ||||
when Task::STATUS_COMPLETE | ||||
"complete" | ||||
end | ||||
end | ||||
|
r30 | def self.get_inqueue_and_change_status(status) | ||
task = nil | ||||
begin | ||||
Task.transaction do | ||||
task = Task.find(:first, | ||||
:order => "created_at", | ||||
:conditions => {:status=> Task::STATUS_INQUEUE}, | ||||
:lock => true) | ||||
if task!=nil | ||||
task.status = status | ||||
task.save! | ||||
end | ||||
end | ||||
rescue | ||||
task = nil | ||||
end | ||||
task | ||||
end | ||||
|
r0 | end | ||