lib/mongoid/locker.rb in mongoid-locker-0.3.0 vs lib/mongoid/locker.rb in mongoid-locker-0.3.1

- old
+ new

@@ -15,11 +15,11 @@ # A scope to retrieve all unlocked documents in the collection. # # @return [Mongoid::Criteria] def unlocked - any_of({ locked_until: nil }, { :locked_until.lte => Time.now }) + any_of({ locked_until: nil }, :locked_until.lte => Time.now) end # Set the default lock timeout for this class. Note this only applies to new locks. Defaults to five seconds. # # @param [Fixnum] new_time the default number of seconds until a lock is considered "expired", in seconds @@ -134,9 +134,11 @@ if attempts_left > 0 # if not passed a retry_sleep value, we sleep for the remaining life of the lock unless opts[:retry_sleep] locked_until = Mongoid::Locker::Wrapper.locked_until(self) + # the lock might be released since the last check so make another attempt + next unless locked_until retry_sleep = locked_until - Time.now end sleep retry_sleep if retry_sleep > 0 else