diff --git a/lib/delayed/backend/mongoid.rb b/lib/delayed/backend/mongoid.rb index 11da91b..e778dcb 100644 --- a/lib/delayed/backend/mongoid.rb +++ b/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