【发布时间】:2014-09-14 22:58:38
【问题描述】:
我需要随时在 Heroku 中运行计划任务。我在 Rails 中的第一份 cron 工作! :-)
它在本地运行良好,但你如何让它在 Heroku 中运行?
我试过这个: heroku 在 --update-crontab 存储时运行
但是……
[失败] 无法编写 crontab;尝试在没有选项的情况下运行 `whenever' 以确保您的计划文件有效。
我还在 Heroku 中的应用中添加了 Heroku Scheduler。
这是我的 config/schedule.rb
RAILS_ROOT = File.dirname(__FILE__) + '/..'
require File.expand_path(File.dirname(__FILE__) + "/environment")
every :day, :at => "11:00am" do
@appointments = Appointment.where('date between ? and ?', Date.today, Date.today + 2.day)
@appointments.each do |appointment|
@emails = []
@informated_people = InformatedPerson.where(person_id: appointment.person_id)
@users = User.find(Authorization.where(:person_id => appointment.person_id).pluck(:user_id))
@person = Person.find(appointment.person_id)
@emails << @person.email
@informated_people.each do |informated_person|
@emails << informated_person.email
end
@users.each do |user|
@emails << user.email
end
UserEmail.appointment_reminder_email(@emails.uniq, @person , 'Cita para el día ' + appointment.date.strftime("%d/%m/%Y %H:%M") + ' con el doctor ' + appointment.doctor + ' para la especialidad ' + appointment.specialty + ' en el centro ' + appointment.center + '.' ).deliver
end
end
【问题讨论】:
标签: ruby-on-rails heroku ruby-on-rails-4 whenever