Search code examples
herokucronschedulerresquerake-task

Heroku scheduler Resque


I have a ruby on rails app (1.9.2 and 3.2) running on Heroku with Redis/Resque that requires a rake task be enqueued at regular intervals. Right now I am running 'heroku run rake update_listings' from my local machine once or twice a day....I would like to automate this. I've tried the whenever gem, but the task would not start up in the background. Heroku scheduler seems like the appropriate solution, but I am confused by the scheduler.rb file. I have:

desc "This task is called by the Heroku scheduler add-on"
task :hourly_feed => :environment do
  Rake::Task[update_listings].execute
end

When I ran the :hourly_feed task from the Heroku Scheduler console and checked heroku logs, I saw several web dynos get spun up by hirefireapp, but the update_listings rake task was never invoked.

Update: I gave up on resque_scheduler. I am too green to make this work, so trying to use crontab and a sript file. Here is my update.sh script file:

Rake::Task["update_listings"].execute

I set cron using crontab-e and I have it executed every 5 minutes, but I get an error in mail logs:

Projects/livebytransit/update.sh: line 1: Rake::Task[update_listings].execute: command not found

It appears it is finding my update.sh script file and reading it, but it is not executing the code. I noticed the log entry dropped the quotes, so I also tried using single quotes in the shell script file, no change. I also tried changing the update.sh to this:

heroku run rake update_listings

error came back heroku: command not found


Solution

  • It turns out the Heroku Scheduler works perfectly...I simply forgot the quotes around "updated listings".