Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a version check for Rails whether to use pg interval or calculate float #1389

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/good_job/base_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def perform(lock_id:)
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_execution_attrs[:duration] = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a')
discrete_executions.where(finished_at: nil).where.not(performed_at: nil).update_all(discrete_execution_attrs) # rubocop:disable Rails/SkipsModelValidations
end
end
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion app/models/good_job/discrete_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/app/models/good_job/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down