Module: WithAdvisoryLock::Concern::ClassMethods

Defined in:
lib/with_advisory_lock/concern.rb

Instance Method Summary collapse

Instance Method Details

#advisory_lock_exists?(lock_name) ⇒ Boolean


19
20
21
22
# File 'lib/with_advisory_lock/concern.rb', line 19

def advisory_lock_exists?(lock_name)
  impl = impl_class.new(connection, lock_name, 0)
  impl.already_locked? || !impl.yield_with_lock.lock_was_acquired?
end

#current_advisory_lockObject


24
25
26
# File 'lib/with_advisory_lock/concern.rb', line 24

def current_advisory_lock
  WithAdvisoryLock::Base.lock_stack.first
end

#with_advisory_lock(lock_name, timeout_seconds = nil, &block) ⇒ Object


9
10
11
12
# File 'lib/with_advisory_lock/concern.rb', line 9

def with_advisory_lock(lock_name, timeout_seconds=nil, &block)
  result = with_advisory_lock_result(lock_name, timeout_seconds, &block)
  result.lock_was_acquired? ? result.result : false
end

#with_advisory_lock_result(lock_name, timeout_seconds = nil, &block) ⇒ Object


14
15
16
17
# File 'lib/with_advisory_lock/concern.rb', line 14

def with_advisory_lock_result(lock_name, timeout_seconds=nil, &block)
  impl = impl_class.new(connection, lock_name, timeout_seconds)
  impl.with_advisory_lock_if_needed(&block)
end