From 38f575843e653cb4d030733041a1e2f39ab8fcf4 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Mon, 8 Jul 2024 20:04:56 +0200 Subject: [PATCH] Fix a rails deprecation warning for the duration attribute (#1408) ``` DEPRECATION WARNING: The behavior of the `:interval` type will be changing in Rails 7.0 to return an `ActiveSupport::Duration` object. If you'd like to keep the old behavior, you can add this line to GoodJob::Execution model: attribute :duration, :string If you'd like the new behavior today, you can add this line: attribute :duration, :interval (called from block (3 levels) in perform at /home/runner/work/good_job/good_job/app/models/good_job/base_execution.rb:440) ``` --- app/models/good_job/discrete_execution.rb | 3 +++ spec/app/models/good_job/job_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/good_job/discrete_execution.rb b/app/models/good_job/discrete_execution.rb index adc54825..e27483df 100644 --- a/app/models/good_job/discrete_execution.rb +++ b/app/models/good_job/discrete_execution.rb @@ -14,6 +14,9 @@ class DiscreteExecution < BaseRecord alias_attribute :performed_at, :created_at + # TODO: Remove when support for Rails 6.1 is dropped + attribute :duration, :interval + def number serialized_params.fetch('executions', 0) + 1 end diff --git a/spec/app/models/good_job/job_spec.rb b/spec/app/models/good_job/job_spec.rb index 0067eee1..63afcabe 100644 --- a/spec/app/models/good_job/job_spec.rb +++ b/spec/app/models/good_job/job_spec.rb @@ -972,7 +972,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: be_a(ActiveSupport::Duration), error: nil, serialized_params: good_job.serialized_params ) @@ -1011,7 +1011,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: be_a(ActiveSupport::Duration) ) end end @@ -1036,7 +1036,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: be_a(ActiveSupport::Duration) ) end end