I have a rails app that have model called Project. I need to go through all the projects every day and call method "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?
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. Inside the rake task you can visit your model as usual.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.