Heroku Cron 将不会运行
所以,我在 heroku 上运行一个简单的 cron 任务。然而,它不起作用。我不断在日志中看到这个:
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
我的 cron.rake 文件(每 4 小时执行一次 put)
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
不知道为什么它不执行 put。另外,一旦这有效,我想经常从我的模型中调用函数。如果我的模型是 Micropost 并且函数是 has_fun 我可以在 cron.rake 中使用... Micropost.has_fun 来调用它吗?
任何帮助将不胜感激。 Stack Overflow 上的人们对我学习 Rails 提供了难以置信的帮助。再次感谢。
更新: 我将 put 更改为:
UserMailer.registration_confirmation().deliver
但是,这会产生相同的日志输出。我已经用actionmailer多次测试了registration_confirmation电子邮件,它们可以使用上述功能。 (电子邮件在 user_mailer.rb 中被编码为静态。
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... 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Thoughtbot 不久前发表了一篇博文,概述了一种方法使用 RSpec、Timecop 和 Bourne 在本地测试 Heroku cron 作业。
Thoughtbot made a blog post not too long ago outlining a method to test Heroku cron jobs locally using RSpec, Timecop, and Bourne.
您应该尝试 rufus 调度程序:
安装 gem
确保您将 gem 包含在捆绑器中,或者以任何方式包含它。
然后,您需要创建一个名为
task_scheduler.rb
的文件,并将其粘贴到您的initializers
目录中。如果您遇到任何问题,可以查看此博客文章:
http://intridea.com/2009/2/13/dead-simple-task-scheduling-in-rails?blog=company
You should try rufus scheduler:
Install the gem
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 youinitializers
directory.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