[英]Calling all model instances from cron
I have a rails app that have model called Project. 我有一个名为Project的Rails应用程序。 I need to go through all the projects every day and call method "project_due?".
我需要每天遍历所有项目并调用方法“ project_due?”。
I guess I would need to use Whenever gem to create cron job, but I am lost in next step: what is the correct way to access the model instances? 我想我将需要使用每当每当gem来创建cron作业,但是我迷失了下一步:访问模型实例的正确方法是什么?
Edit: model code, it is actually quite simple: 编辑:模型代码,它实际上很简单:
class Project < ActiveRecord::Base
def need_new_forecast?
d = self.forecasts.last.date_stamp || Date.today
return Date.today.beginning_of_week > d.beginning_of_week
end
end
I need to go through all Projects every day to check which project needs new forecast (then I will email user and so forth). 我需要每天检查所有项目,以检查哪个项目需要新的预测(然后我将通过电子邮件向用户发送电子邮件,等等)。 The code is simplified, there are other cases in my app: things like daily/monthly/quarterly forecasts
代码经过简化,我的应用中还有其他情况:例如每日/每月/每季度的预测
you can use cron to invoke a rake task. 您可以使用cron调用rake任务。 Inside the rake task you can visit your model as usual.
在rake任务中,您可以照常访问模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.