Show More
Commit Description:
change find(:xxx) to correct syntax for rails 4
Commit Description:
change find(:xxx) to correct syntax for rails 4
References:
File last commit:
Show/Diff file:
Action:
app/models/task.rb
| 65 lines
| 1.0 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 | ||||
r619 | task = Task.where(status: Task::STATUS_INQUEUE).where(lock: true).first | |||
|
r30 | if task!=nil | ||
task.status = status | ||||
task.save! | ||||
end | ||||
end | ||||
rescue | ||||
task = nil | ||||
end | ||||
task | ||||
end | ||||
|
r0 | end | ||