diff --git a/app/models/good_job/base_execution.rb b/app/models/good_job/base_execution.rb index 0120795e..51fc8876 100644 --- a/app/models/good_job/base_execution.rb +++ b/app/models/good_job/base_execution.rb @@ -602,7 +602,7 @@ def perform(lock_id:) job_attributes[:finished_at] = job_finished_at if discrete_execution discrete_execution.finished_at = job_finished_at - discrete_execution.duration = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? + discrete_execution.duration = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') end retry_unhandled_error = result.unhandled_error && GoodJob.retry_on_unhandled_error diff --git a/app/models/good_job/discrete_execution.rb b/app/models/good_job/discrete_execution.rb index 7f2e0097..56654bd2 100644 --- a/app/models/good_job/discrete_execution.rb +++ b/app/models/good_job/discrete_execution.rb @@ -46,7 +46,8 @@ def queue_latency # Monotonic time between when this job started and finished def runtime_latency - if self.class.monotonic_duration_migrated? + # migrated and Rails greater than 6.1 + if self.class.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') duration elsif performed_at (finished_at || Time.current) - performed_at diff --git a/spec/app/models/good_job/execution_spec.rb b/spec/app/models/good_job/execution_spec.rb index 80d706d2..9853156c 100644 --- a/spec/app/models/good_job/execution_spec.rb +++ b/spec/app/models/good_job/execution_spec.rb @@ -702,7 +702,7 @@ def job_params created_at: within(0.001).of(good_job.performed_at), scheduled_at: within(0.001).of(good_job.created_at), finished_at: within(1.second).of(Time.current), - duration: be_present, + duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, error: nil, serialized_params: good_job.serialized_params ) @@ -741,7 +741,7 @@ def job_params created_at: within(1.second).of(Time.current), scheduled_at: within(1.second).of(Time.current), finished_at: within(1.second).of(Time.current), - duration: be_present + duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil ) end end @@ -766,7 +766,7 @@ def job_params expect(good_job.discrete_executions.first).to have_attributes( performed_at: within(1.second).of(Time.current), finished_at: within(1.second).of(Time.current), - duration: be_present + duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil ) end end diff --git a/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb b/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb index 2bd692a3..ad92cbf3 100644 --- a/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb +++ b/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb @@ -83,7 +83,7 @@ def perform expect(initial_discrete_execution).to have_attributes( performed_at: be_present, finished_at: be_present, - duration: be_present, + duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, error: start_with('GoodJob::InterruptError: Interrupted after starting perform at'), error_event: GoodJob::Job::ERROR_EVENT_INTERRUPTED ) @@ -92,7 +92,7 @@ def perform expect(retried_discrete_execution).to have_attributes( performed_at: be_present, finished_at: be_present, - duration: be_present, + duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, error: start_with('GoodJob::InterruptError: Interrupted after starting perform at'), error_event: GoodJob::Job::ERROR_EVENT_RETRIED )