Heroku/Rails:任务调度程序正在工作,但什么也不做

问题描述 投票:0回答:1

我有一个在 Heroku 上运行的应用程序,它每天运行一次名为 every_day 的任务。任务计划程序工作正常,但它对我的数据库没有任何作用。我也尝试手动运行它,结果是一样的。我认为问题出在我的代码上,如果有人能告诉我出了什么问题,我将不胜感激。此任务代码:

task :every_day => :environment do
  unactive_auction = Auction.where(ended: false).where('created_at < ?', 14.days.ago)
  unactive_auction.update_all(:ended => true)
end

当我手动运行它时,我得到这个:

, [2017-06-07T07:08:26.348223 #4] DEBUG -- :   Auction Load (1.7ms)  SELECT  "auctions".* FROM "auctions" ORDER BY "auctions"."id" ASC LIMIT $1  [["LIMIT", 1000]]
D, [2017-06-07T07:08:26.677182 #4] DEBUG -- :   SQL (1.3ms)  UPDATE "auctions" SET "ended" = 't' WHERE "auctions"."ended" = $1 AND (created_at < '2017-05-24 07:08:26.674476')  [["ended", false]]

我不知道我做错了什么。看起来它正在工作,但是......但它什么也没做。

ruby-on-rails heroku scheduled-tasks
1个回答
1
投票

您确定有满足您的查询参数的对象吗? 在rails控制台中运行:

 unactive_auction = Auction.where("ended is ? and created_at < ?", false, 14.days.ago)

并在运行任务之前查看它是否返回任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.