ruby 在Rails 7.1.0.rc1中不推荐使用scheduled_at的数字/纪元值

jogvjijk  于 12个月前  发布在  Ruby
关注(0)|答案(1)|浏览(79)

我在升级到Rails 7.1时收到了一个弃用警告,谷歌没有搜索结果!
警告为DEPRECATION WARNING: Assigning a numeric/epoch value to scheduled_at is deprecated. Use a Time object instead.
这是在我们使用wait_until调度后台作业时引发的。我们在测试中传递的值是1.month.from.now,它给出了一个时间值。
我认为这一行提出了警告:

NotifyAudienceJob.set(wait_until: published_at).perform_later(audience.id)

以及触发警告的测试:

test 'creating audiences for a scheduled article with notifications enabled should schedule notifications' do
    @article.update!(published_at: 1.month.from_now)

    assert_enqueued_with(job: NotifyAudienceJob) do
      post admin_news_feed_article_audiences_url(@article), params: { whole_organisation: true }
    end
  end

有没有人对解决这个问题有什么建议?
警告来自ActiveJob中的此行
注意:这在Rails 7.1.0.rc2中已修复

kxe2p93d

kxe2p93d1#

将此对象转换为前面提到的Time对象

1.month.from_now.to_time

现在它不是Time对象

1.month.from_now.class # => ActiveSupport::TimeWithZone
1.month.from_now.to_time.class # => Time

相关问题