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 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',