Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/with_advisory_lock/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ module WithAdvisoryLock
class PostgreSQL < Base
# See http://www.postgresql.org/docs/9.1/static/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
def try_lock
execute_successful?('pg_try_advisory_lock')
if connection.open_transactions > 0
execute_successful?('pg_try_advisory_xact_lock')
else
execute_successful?('pg_try_advisory_lock')
end
end

def release_lock
execute_successful?('pg_advisory_unlock')
if connection.open_transactions <= 0
execute_successful?('pg_advisory_unlock')
end
end

def execute_successful?(pg_function)
Expand Down