Skip to content

Commit

Permalink
Fix a rails deprecation warning for the duration attribute (#1408)
Browse files Browse the repository at this point in the history
```
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)
```
  • Loading branch information
Earlopain authored Jul 8, 2024
1 parent 9a1eb0b commit 38f5758
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/models/good_job/discrete_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/app/models/good_job/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 38f5758

Please sign in to comment.