首先,每当和克伦是同义词。所有无论何时提供一种方法让你使用Ruby编写cronjobs(这真是太棒了,我喜欢Whenever)。
Delayed_job不是这里的答案。你一定要使用cronjobs。在您的应用程序模型上创建一个方法,该方法将获得updated_at
值为< 2.days.ago
的应用程序,并通过电子邮件向其申请人发送电子邮件。
def notify_stale_applicants
@stale_applications = Application.where('updated_at < ?', 2.days.ago) # or 48.hours.ago
@stale_applications.each do |app|
UserMailer.notify_is_stale(app).deliver
end
end
而且你UserMailer:
def notify_is_stale(application)
@application = application
mail(:to => application.user.email, :from => "Application Status <[email protected]>", :subject => "You haven't finished your Application!"
end
使用时创建此的cron:
every :day, :at => '8am' do
runner 'Application.notify_stale_applicants'
end