From eceebcc7a2b29799f33543bbf633c381727fccad Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Fri, 5 Jul 2024 18:30:01 -0700 Subject: [PATCH] Add a version check for Rails whether to use pg interval or calculate float --- app/models/good_job/discrete_execution.rb | 3 ++- app/models/good_job/execution.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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/app/models/good_job/execution.rb b/app/models/good_job/execution.rb index 3b1a1f3c..b06d04c4 100644 --- a/app/models/good_job/execution.rb +++ b/app/models/good_job/execution.rb @@ -501,7 +501,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