From e50450e5deaa3fab9acb1d02495219058966def1 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 3 Mar 2024 19:09:15 +0100 Subject: [PATCH 1/2] feat: add release_all_locks --- lib/with_advisory_lock/mysql.rb | 4 ++++ lib/with_advisory_lock/postgresql.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/with_advisory_lock/mysql.rb b/lib/with_advisory_lock/mysql.rb index 3ca8ef9..7f74df9 100644 --- a/lib/with_advisory_lock/mysql.rb +++ b/lib/with_advisory_lock/mysql.rb @@ -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 diff --git a/lib/with_advisory_lock/postgresql.rb b/lib/with_advisory_lock/postgresql.rb index 9ec31d6..be2183c 100644 --- a/lib/with_advisory_lock/postgresql.rb +++ b/lib/with_advisory_lock/postgresql.rb @@ -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', From 2e1b953662f81f0ec5a18530d6ae64facb4c372a Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Sun, 3 Mar 2024 19:19:18 +0100 Subject: [PATCH 2/2] feat!: rename impl_class to with_advisory_impl_class fixes #83 --- lib/with_advisory_lock/concern.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/with_advisory_lock/concern.rb b/lib/with_advisory_lock/concern.rb index 66587ce..005aeb0 100644 --- a/lib/with_advisory_lock/concern.rb +++ b/lib/with_advisory_lock/concern.rb @@ -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 @@ -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