Module: ActiveRecord::DatabaseMutex::ClassMethods

Defined in:
lib/active_record/database_mutex.rb

Instance Method Summary collapse

Instance Method Details

#all_mutexesArray

The all_mutexes method returns an array of MutexInfo objects representing all mutexes currently held by database connections. The MutexInfo#OBJECT_NAME is the Implementation#internal_name.

Returns:

  • (Array)

    An array of MutexInfo objects.



75
76
77
78
79
80
81
# File 'lib/active_record/database_mutex.rb', line 75

def all_mutexes
  connection.select_all(<<~EOT).map { MutexInfo.new(_1) }
    SELECT * FROM performance_schema.metadata_locks
    WHERE OBJECT_TYPE = 'USER LEVEL LOCK'
    AND OBJECT_NAME LIKE "$%"
  EOT
end

#mutexActiveRecord::DatabaseMutex::Implementation

The mutex method returns an instance of ActiveRecord::DatabaseMutex::Implementation that is initialized with the name given by the class and environment variables.

Returns:



65
66
67
# File 'lib/active_record/database_mutex.rb', line 65

def mutex
  @mutex ||= Implementation.new(name: mutex_name)
end

#mutex_nameObject



56
57
58
# File 'lib/active_record/database_mutex.rb', line 56

def mutex_name
  @mutex_name ||= [ name, defined?(Rails) ? Rails.env : ENV['RAILS_ENV'] ].compact * ?@
end