From b11872e03023708de7ece91a735b3d98ead7dfc1 Mon Sep 17 00:00:00 2001 From: Vladimir Lyzo Date: Fri, 21 Apr 2023 14:19:40 +1000 Subject: [PATCH] raise exception if not in transaction better message --- lib/with_advisory_lock/postgresql.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/with_advisory_lock/postgresql.rb b/lib/with_advisory_lock/postgresql.rb index ae369cb..bcb9b31 100644 --- a/lib/with_advisory_lock/postgresql.rb +++ b/lib/with_advisory_lock/postgresql.rb @@ -5,6 +5,9 @@ class PostgreSQL < Base # See http://www.postgresql.org/docs/9.1/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS def try_lock pg_function = "pg_try_advisory#{transaction ? '_xact' : ''}_lock#{shared ? '_shared' : ''}" + + raise "#{pg_function} requires transaction" if transaction && !ActiveRecord::Base.within_transaction? + execute_successful?(pg_function) end