I have written a rake task that updates the time on the reminders in my program to the next day.
namespace :add_day do
desc "add day to reminders"
task :ad => :environment do
# grab all reminders
reminders = Reminder.all
puts reminders
# add one day to reminders
reminders.each do |r|
puts r.time
r.time = r.time + 60*60*24
puts r.time
r.save!
puts "saved"
# reschedule reminders
r.reminder
puts "reminder sent"
end
end
end
This task runs locally, completing without any errors. However when I try to run it on heroku, it errors out. Run locally, the console outputs:
#<Reminder:0x007fa17d2ed698>
#<Reminder:0x007fa17d2ed4e0>
#<Reminder:0x007fa17d2ed238>
2015-07-27 01:20:00 UTC
2015-07-28 01:20:00 UTC
saved
reminder sent
2015-07-24 19:53:00 UTC
2015-07-25 19:53:00 UTC
saved
reminder sent
2015-07-24 20:25:00 UTC
2015-07-25 20:25:00 UTC
saved
reminder sent
The Heroku console outputs:
#<Reminder:0x007f29366a0408>
#<Reminder:0x007f29366a00e8>
#<Reminder:0x007f29366a7d48>
2015-07-20 22:40:00 UTC
2015-07-21 22:40:00 UTC
saved
rake aborted!
Heroku::API::Errors::NotFound: Expected(200) <=> Actual(404 Not Found)
body: "App not found."
And the heroku logs are:
2015-07-15T13:48:46.144676+00:00 heroku[api]: Starting process with command `bundle exec rake add_day:ad` by [email protected]
2015-07-15T13:48:51.262221+00:00 heroku[run.4172]: State changed from starting to up
2015-07-15T13:48:51.585926+00:00 heroku[run.4172]: Awaiting client
2015-07-15T13:48:51.944009+00:00 heroku[run.4172]: Starting process with command `bundle exec rake add_day:ad`
2015-07-15T13:49:06.273951+00:00 heroku[run.4172]: Process exited with status 1
2015-07-15T13:49:06.290969+00:00 heroku[run.4172]: State changed from up to complete
All other rake tasks (db:migrate...) work correctly, and the "app not found" error doesn't show up in any other circumstance.
Do you know why this could be happening? No one else seems to have this same problem on stack overflow
thanks
So it was getting stuck on adding the delayed job to the queue ( that's what r.reminder does). I'm using the workless gem and the "App not found" error meant that workless couldn't find the app with the APP_NAME env variable on heroku. I had it set to the name of the git repo not the heroku generated name. Once I switched it everything worked fine.