Skip to content

Commit

Permalink
raise exception if not in transaction
Browse files Browse the repository at this point in the history
better message
  • Loading branch information
donbobka committed Apr 21, 2023
1 parent 00f1cfe commit 727cbeb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/with_advisory_lock/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" unless ActiveRecord::Base.within_transaction?

execute_successful?(pg_function)
end

Expand Down

0 comments on commit 727cbeb

Please sign in to comment.