I need to run a scheduled task in Heroku using whenever. My first cron job in Rails! :-)
It works fine locally, but how do you make it work in Heroku?
I tried this: heroku run whenever --update-crontab store
but...
[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid.
I also added Heroku Scheduler to my app in Heroku.
This is my 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