Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add release_all_locks for connection and impl_class #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/with_advisory_lock/concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ def with_advisory_lock!(lock_name, options = {}, &block)
end

def with_advisory_lock_result(lock_name, options = {}, &block)
impl = impl_class.new(connection, lock_name, options)
impl = with_advisory_lock_impl_class.new(connection, lock_name, options)
impl.with_advisory_lock_if_needed(&block)
end

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

Expand All @@ -35,7 +35,7 @@ def current_advisory_lock

private

def impl_class
def with_advisory_lock_impl_class
adapter = WithAdvisoryLock::DatabaseAdapterSupport.new(connection)
if adapter.postgresql?
WithAdvisoryLock::PostgreSQL
Expand Down
4 changes: 4 additions & 0 deletions lib/with_advisory_lock/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def release_lock
execute_successful?("RELEASE_LOCK(#{quoted_lock_str})")
end

def release_all_locks
execute_query("RELEASE_ALL_LOCKS()")
end

def execute_successful?(mysql_function)
execute_query(mysql_function) == 1
end
Expand Down
4 changes: 4 additions & 0 deletions lib/with_advisory_lock/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def release_lock
end
end

def release_all_locks
connection.execute("SELECT pg_advisory_unlock_all()")
end

def advisory_try_lock_function(transaction_scope)
[
'pg_try_advisory',
Expand Down
Loading