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