lib/good_job/job.rb in good_job-1.3.5 vs lib/good_job/job.rb in good_job-1.3.6
- old
+ new
@@ -137,11 +137,11 @@
error = nil
unfinished.priority_ordered.only_scheduled.limit(1).with_advisory_lock do |good_jobs|
good_job = good_jobs.first
# TODO: Determine why some records are fetched without an advisory lock at all
- break unless good_job&.owns_advisory_lock?
+ break unless good_job&.executable?
result, error = good_job.perform
end
[good_job, result, error] if good_job
@@ -212,9 +212,15 @@
else
destroy!
end
[result, job_error]
+ end
+
+ # Tests whether this job is safe to be executed by this thread.
+ # @return [Boolean]
+ def executable?
+ self.class.unscoped.unfinished.owns_advisory_locked.exists?(id: id)
end
private
def execute