Skip to content

Commit 727cbeb

Browse files
committed
raise exception if not in transaction
better message
1 parent 00f1cfe commit 727cbeb

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/with_advisory_lock/postgresql.rb

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class PostgreSQL < Base
55
# See http://www.postgresql.org/docs/9.1/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
66
def try_lock
77
pg_function = "pg_try_advisory#{transaction ? '_xact' : ''}_lock#{shared ? '_shared' : ''}"
8+
9+
raise "#{pg_function} requires transaction" unless ActiveRecord::Base.within_transaction?
10+
811
execute_successful?(pg_function)
912
end
1013

0 commit comments

Comments
 (0)