我在 Heroku 中正确运行我的 cron 任务吗?
不确定我这样做是否正确。阅读:http://devcenter.heroku.com/articles/cron#frequently-asked -questions
如果我有 cron 每 24 小时在 Heroku 上运行一次。它会每 24 小时运行一次 def foo
和 def bar
吗?或者我应该用 if Time.now.hour % 24== 0 # run every 24 hour
包装这两个方法?
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
def foo
puts 'foo'
end
deb bar
puts 'bar'
end
end
其次,如何在本地计算机上运行此 cron 作业(可能通过控制台或其他方法)?
附言。我在 Cedar 堆栈上运行 Rails 3.1 RC5。
Not sure if I am doing this right. Reading: http://devcenter.heroku.com/articles/cron#frequently-asked-questions
If I have cron running every 24 hours on Heroku. Will it run def foo
and def bar
every 24 hours? Or should I wrap both methods with if Time.now.hour % 24== 0 # run every 24 hours
?
desc "This task is called by the Heroku cron add-on"
task :cron => :environment do
def foo
puts 'foo'
end
deb bar
puts 'bar'
end
end
Second, how can I run this cron job on my local machine (possibly via console or other method)?
PS. I am running Rails 3.1 RC5 on the Cedar stack.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您将 cron 设置为“每日”,那么它将每 24 小时运行一次,无需在其中添加 if 语句。
要在本地运行 cron 任务,只需执行
rake cron
编辑:
您还需要调用您在其中定义的方法,因为当前 cron 所做的只是定义 foo 和 bar:
If you've set up the cron as "daily" then it will run every 24 hours, there's no need to put an if statement in there.
To run the cron task locally just do
rake cron
Edit:
You'll also need to call the methods you've defined in there as currently all your cron does is define foo and bar: