app/models/good_job/execution.rb in good_job-3.29.5 vs app/models/good_job/execution.rb in good_job-3.30.0

- old
+ new

@@ -370,10 +370,11 @@ def perform(lock_id:) run_callbacks(:perform) do raise PreviouslyPerformedError, 'Cannot perform a job that has already been performed' if finished_at job_performed_at = Time.current + monotonic_start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) discrete_execution = nil result = GoodJob::CurrentThread.within do |current_thread| current_thread.reset current_thread.execution = self @@ -383,16 +384,18 @@ if discrete? interrupt_error_string = self.class.format_error(GoodJob::InterruptError.new("Interrupted after starting perform at '#{existing_performed_at}'")) self.error = interrupt_error_string self.error_event = ERROR_EVENT_INTERRUPTED if self.class.error_event_migrated? + monotonic_duration = (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - monotonic_start).seconds discrete_execution_attrs = { error: interrupt_error_string, finished_at: job_performed_at, } discrete_execution_attrs[:error_event] = GoodJob::ErrorEvents::ERROR_EVENT_ENUMS[GoodJob::ErrorEvents::ERROR_EVENT_INTERRUPTED] if self.class.error_event_migrated? + discrete_execution_attrs[:duration] = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? discrete_executions.where(finished_at: nil).where.not(performed_at: nil).update_all(discrete_execution_attrs) # rubocop:disable Rails/SkipsModelValidations end end if discrete? @@ -492,11 +495,15 @@ job_attributes[:error_event] = nil end job_attributes.delete(:error_event) unless self.class.error_event_migrated? job_finished_at = Time.current + monotonic_duration = (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - monotonic_start).seconds job_attributes[:finished_at] = job_finished_at - discrete_execution.finished_at = job_finished_at if discrete_execution + if discrete_execution + discrete_execution.finished_at = job_finished_at + discrete_execution.duration = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? + end retry_unhandled_error = result.unhandled_error && GoodJob.retry_on_unhandled_error reenqueued = result.retried? || retried_good_job_id.present? || retry_unhandled_error if reenqueued if discrete_execution