module Mongoid::Locker::ClassMethods
Public Instance Methods
Source
# File lib/mongoid/locker.rb, line 134 def locked where( '$and': [ { locking_name_field => { '$exists': true, '$ne': nil } }, { locked_at_field => { '$gte': Time.now.utc - (lock_timeout * 1000) } } ] ) end
A scope to retrieve all locked documents in the collection.
@example
Account.count #=> 1717 Account.locked.count #=> 17
@return [Mongoid::Criteria]
Source
# File lib/mongoid/locker.rb, line 203 def locker(**params) invalid_parameters = params.keys - Mongoid::Locker.singleton_class.const_get('MODULE_METHODS') raise Mongoid::Locker::Errors::InvalidParameter.new(self.class, invalid_parameters.first) unless invalid_parameters.empty? params.each_pair do |key, value| send("#{key}=", value) end end
Sets configuration for this class.
@example
locker locking_name_field: :locker_locking_name, locked_at_field: :locker_locked_at, lock_timeout: 3, locker_write_concern: { w: 1 }, maximum_backoff: 30.0, backoff_algorithm: :locked_at_backoff, locking_name_generator: :custom_locking_name
@param locking_name_field [Symbol] @param locked_at_field [Symbol] @param maximum_backoff [Float, Integer] @param lock_timeout [Float, Integer] @param locker_write_concern [Hash] @param backoff_algorithm [Symbol] @param locking_name_generator [Symbol]
Source
# File lib/mongoid/locker.rb, line 181 def unlock_all update_all('$set': { locking_name_field => nil, locked_at_field => nil }).modified_count end
Unlock all locked documents in the collection. Sets locking_name_field and locked_at_field fields to nil. Returns number of unlocked documents.
@example
Account.unlock_all #=> 17 Account.locked.unlock_all #=> 0
@return [Integer]
Source
# File lib/mongoid/locker.rb, line 152 def unlocked where( '$or': [ { '$or': [ { locking_name_field => { '$exists': false } }, { locked_at_field => { '$exists': false } } ] }, { '$or': [ { locking_name_field => { '$eq': nil } }, { locked_at_field => { '$eq': nil } } ] }, { locked_at_field => { '$lt': Time.now.utc - (lock_timeout * 1000) } } ] ) end
A scope to retrieve all unlocked documents in the collection.
@example
Account.count #=> 1717 Account.unlocked.count #=> 1700
@return [Mongoid::Criteria]