app/models/good_job/execution.rb in good_job-3.21.0 vs app/models/good_job/execution.rb in good_job-3.21.1

- old
+ new

@@ -246,32 +246,31 @@ execution_args.merge(overrides) end # Finds the next eligible Execution, acquire an advisory lock related to it, and # executes the job. + # @yield [Execution, nil] The next eligible Execution, or +nil+ if none found, before it is performed. # @return [ExecutionResult, nil] # If a job was executed, returns an array with the {Execution} record, the # return value for the job's +#perform+ method, and the exception the job # raised, if any (if the job raised, then the second array entry will be # +nil+). If there were no jobs to execute, returns +nil+. def self.perform_with_advisory_lock(parsed_queues: nil, queue_select_limit: nil) execution = nil result = nil + unfinished.dequeueing_ordered(parsed_queues).only_scheduled.limit(1).with_advisory_lock(select_limit: queue_select_limit) do |executions| execution = executions.first - break if execution.blank? - - unless execution.executable? - result = ExecutionResult.new(value: nil, unexecutable: true) + if execution&.executable? + yield(execution) if block_given? + result = execution.perform + else execution = nil - break + yield(nil) if block_given? end - - yield(execution) if block_given? - result = execution.perform end - execution&.run_callbacks(:perform_unlocked) + execution&.run_callbacks(:perform_unlocked) result end # Fetches the scheduled execution time of the next eligible Execution(s). # @param after [DateTime]