module Mimi::DB::Lock
Public Class Methods
configure(*)
click to toggle source
Calls superclass method
# File lib/mimi/db/lock.rb, line 23 def self.configure(*) super Mimi::DB.extend(self) end
module_path()
click to toggle source
# File lib/mimi/db/lock.rb, line 19 def self.module_path Pathname.new(__dir__).join('lock') end
start()
click to toggle source
Calls superclass method
# File lib/mimi/db/lock.rb, line 28 def self.start require_relative 'lock/postgresql_lock' require_relative 'lock/mysql_lock' require_relative 'lock/sqlite_lock' super end
Public Instance Methods
lock(name, opts = {}, &block)
click to toggle source
Obtains a named lock
@param [String,Symbol] name @param [Hash] opts @option opts [Numeric,nil] :timeout Timeout in seconds @option opts [Boolean] :temporary Remove the lock
@return [true] if the lock was obtained and the block executed @return [Falsey] if the lock was NOT obtained
# File lib/mimi/db/lock.rb, line 45 def lock(name, opts = {}, &block) lock!(name, opts, &block) true rescue NotAvailable nil end
lock!(name, opts = {}, &block)
click to toggle source
# File lib/mimi/db/lock.rb, line 52 def lock!(name, opts = {}, &block) raise 'Not implemented' # FIXME: migrate Mimi::DB::Lock to Sequel opts = Mimi::DB::Lock.module_options[:default_lock_options].merge(opts.dup) adapter_name = ActiveRecord::Base.connection.adapter_name.downcase.to_sym case adapter_name when :postgresql, :empostgresql, :postgis Mimi::DB::Lock::PostgresqlLock.new(name, opts).execute(&block) when :mysql, :mysql2 Mimi::DB::Lock::MysqlLock.new(name, opts).execute(&block) when :sqlite Mimi::DB::Lock::SqliteLock.new(name, opts).execute(&block) else raise "Named locks not supported by the adapter: #{adapter_name}" end end