开发者

Heroku Cron will not run

So, I'm running a simple cron task on heroku. However, it does not work. I keep getting this in the log :

2011-06-15T03:21:35+00:00 heroku[web.1]: State changed from up to bouncing
2011-06-15T03:21:35+00:00 heroku[web.1]: State changed from created to starting
2011-06-15T03:21:35+00:00 heroku[slugc]: Slug compilation finished
2011-06-15T03:21:41+00:00 heroku[web.1]: Starting process with command: `thin -p 5926 -e production -R /home/heroku_rack/heroku.ru start`
2011-06-15T03:21:46+00:00 app[web.1]: >> Thin web server (v1.2.6 codename Crazy Delicious)
2011-06-15T03:21:46+00:00 app[web.1]: >> Maximum connections set to 1024
2011-06-15T03:21:46+00:00 app[web.1]: >> Listening on 0.0.0.0:5926, CTRL+C to stop
2011-06-15T03:21:47+00:00 heroku[web.1]: State changed from starting to up
2011-06-15T03:22:30+00:00 heroku[web.1]: Stopping process with SIGTERM
2011-06-15T03:22:30+00:00 app[web.1]: >> Stopping ...
2011-06-15T03:22:30+00:00 heroku[web.1]: Process exited

My cron.rake file (just does puts every 4 hours)

 desc "This task is called by the Heroku cron add-on"
 task :cron => :environment do
   if Time.now.hour % 4 == 0 # run every four hours
     puts "Sending email of most popular post."
     puts "done."
   end
 end

Not sure why it wouldn't just do the puts. Also, once this works I want to call functions from my models every so often. If my model was Micropost and the function was has_fun could I call it with... 开发者_StackOverflow社区 Micropost.has_fun in the cron.rake?

Any help would be more than appreciated. The people on stack overflow have been an incredible help for me learning rails. Thanks again.

Update: I changed the puts to:

UserMailer.registration_confirmation().deliver

However, this results in the same log output. I have tested registration_confirmation emails with actionmailer multiple times and they work with the above function. (the email is coded as static in the user_mailer.rb.


You should try rufus scheduler:

Install the gem

 gem install rufus-scheduler

Make sure you include the gem in bundler or however you are including it.

Then you need to create a file called task_scheduler.rb and stick this in you initializers directory.

 require 'rufus/scheduler'
 scheduler = Rufus::Scheduler.start_new

 scheduler.every '10m' do

      puts "Test!"      
      #do something here

 end

If you have any trouble you can see this blog post:

http://intridea.com/2009/2/13/dead-simple-task-scheduling-in-rails?blog=company


Thoughtbot made a blog post not too long ago outlining a method to test Heroku cron jobs locally using RSpec, Timecop, and Bourne.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜