Skip to content

Commit

Permalink
Merge pull request #37 from romanbsd/mongoid-2
Browse files Browse the repository at this point in the history
Instead of performing a redundant query, just wrap the result
  • Loading branch information
sferik committed Apr 8, 2013
2 parents 5d8e20b + 4b1fbec commit d74a0b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/delayed/backend/mongoid.rb
Expand Up @@ -67,8 +67,10 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
) )


# Return result as a Mongoid document. # Return result as a Mongoid document.
# When Mongoid starts supporting findAndModify, this extra step should no longer be necessary. new.tap do |job|
self.find(:first, :conditions => {:_id => result["_id"]}) unless result.nil? job.new_record = false
job.assign_attributes(result)
end unless result.nil?
rescue Mongo::OperationFailure rescue Mongo::OperationFailure
nil # no jobs available nil # no jobs available
end end
Expand Down

0 comments on commit d74a0b9

Please sign in to comment.