Skip to content

Instantly share code, notes, and snippets.

@atnan
Created June 23, 2009 13:07
Show Gist options
  • Save atnan/134520 to your computer and use it in GitHub Desktop.
Save atnan/134520 to your computer and use it in GitHub Desktop.
class Job < ActiveRecord::Base
STATUS_READY, STATUS_IN_PROGRESS, STATUS_DONE = 1, 2, 3
def self.fetch(pid)
update_all(
{ :status => STATUS_IN_PROGRESS,
:pid => pid },
{ :status => STATUS_READY },
{ :limit => 1,
:order => 'created_at asc' })
find_by_status_and_pid STATUS_IN_PROGRESS, pid
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment