1

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

tomb
  • 1,374
  • 1
  • 13
  • 23

2 Answers2

0

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

tomb
  • 1,374
  • 1
  • 13
  • 23
0

Personally, I used resque_scheduler, which will add jobs to the resque / redis queue using cron.

resque_schedule.yml

count_delayed_jobs_job:
 cron: "0 */1 * * *"
 class: Support::CountDelayedJobsResque
 queue: CDJ
 args: 
 description: "count_delayed_jobs_job, every 1hr"

alternatively, you could just chuck Rake::Task["update_listings"].execute in a shell script and use crontab to trigger the job.

TomDunning
  • 4,829
  • 1
  • 26
  • 33
  • Thanks, I updated my question with some issues I ran into attempting a crontab solution. – tomb Jul 15 '12 at 23:26
  • How is your procifle setup to do this @TomDunning http://stackoverflow.com/questions/41537142/heroku-procfile-resque-puma-rails-5-resque-scheduler-setup – Chris Hough Jan 08 '17 at 20:19
  • @chrishough, to do what? Execute the scheduler? That's part of the resque_scheduler gem – TomDunning Jan 09 '17 at 10:33