Permalink
Browse files

Merge pull request #37 from romanbsd/mongoid-2

Instead of performing a redundant query, just wrap the result
  • Loading branch information...
2 parents 5d8e20b + 4b1fbec commit d74a0b911873748d6205c3b1e6a4ed661bdb8741 @sferik sferik committed Apr 8, 2013
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/delayed/backend/mongoid.rb
@@ -67,8 +67,10 @@ def self.reserve(worker, max_run_time = Worker.max_run_time)
)
# Return result as a Mongoid document.
- # When Mongoid starts supporting findAndModify, this extra step should no longer be necessary.
- self.find(:first, :conditions => {:_id => result["_id"]}) unless result.nil?
+ new.tap do |job|
+ job.new_record = false
+ job.assign_attributes(result)
+ end unless result.nil?
rescue Mongo::OperationFailure
nil # no jobs available
end

0 comments on commit d74a0b9

Please sign in to comment.