lib/good_job/lockable.rb in good_job-0.6.0 vs lib/good_job/lockable.rb in good_job-0.7.0
- old
+ new
@@ -35,18 +35,21 @@
scope :advisory_unlocked, -> { joins_advisory_locks.where(pg_locks: { locktype: nil }) }
scope :advisory_locked, -> { joins_advisory_locks.where.not(pg_locks: { locktype: nil }) }
scope :owns_advisory_locked, -> { joins_advisory_locks.where('"pg_locks"."pid" = pg_backend_pid()') }
attr_accessor :create_with_advisory_lock
+
after_create -> { advisory_lock }, if: :create_with_advisory_lock
end
class_methods do
- def with_advisory_lock(&block)
+ def with_advisory_lock
+ raise ArgumentError, "Must provide a block" unless block_given?
+
records = advisory_lock.to_a
begin
- block.call(records)
+ yield(records)
ensure
records.each(&:advisory_unlock)
end
end
end
@@ -71,9 +74,11 @@
result = advisory_lock
result || raise(RecordAlreadyAdvisoryLockedError)
end
def with_advisory_lock
+ raise ArgumentError, "Must provide a block" unless block_given?
+
advisory_lock!
yield
ensure
advisory_unlock unless $ERROR_INFO.is_a? RecordAlreadyAdvisoryLockedError
end