lib/good_job/lockable.rb in good_job-1.10.1 vs lib/good_job/lockable.rb in good_job-1.11.0
- old
+ new
@@ -199,12 +199,19 @@
# all remaining locks).
# @param key [String, Symbol] Key to Advisory Lock against
# @param function [String, Symbol] Postgres Advisory Lock function name to use
# @return [Boolean] whether the lock was acquired.
def advisory_lock(key: lockable_key, function: advisory_lockable_function)
- query = <<~SQL.squish
- SELECT #{function}(('x'||substr(md5($1::text), 1, 16))::bit(64)::bigint) AS locked
- SQL
+ query = if function.include? "_try_"
+ <<~SQL.squish
+ SELECT #{function}(('x'||substr(md5($1::text), 1, 16))::bit(64)::bigint) AS locked
+ SQL
+ else
+ <<~SQL.squish
+ SELECT #{function}(('x'||substr(md5($1::text), 1, 16))::bit(64)::bigint)::text AS locked
+ SQL
+ end
+
binds = [[nil, key]]
self.class.connection.exec_query(pg_or_jdbc_query(query), 'GoodJob::Lockable Advisory Lock', binds).first['locked']
end
# Releases an advisory lock on this record if it is locked by this database