Heroku cron 作业帮助
如何在 cron.rake 中每 15 分钟运行一次任务 reklamer:runall?
I have my cron.rake file:
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 "Updating feed..."
NewsFeed.update
puts "done."
end
How do I run the task reklamer:runall every 15 minutes in cron.rake?
I have my cron.rake file:
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 "Updating feed..."
NewsFeed.update
puts "done."
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Heroku 只提供每日或每小时的 cron 作业,所以我认为每 15 分钟运行一次 cron 作业是不走运的。
相反,您可以使用 delayed_job 每 15 分钟运行一次作业。每次运行结束时,您的作业代码应创建另一个将在 15 分钟内运行的作业。您可以根据您的需要计算从作业开始或结束起的 15 分钟。
Heroku only provides daily or hourly cron jobs so I think you're out of luck with running cron jobs every 15 minutes.
Instead, you could use delayed_job to run jobs every 15 minutes. At the end of each run, your job code should create another job which will run in 15 minutes. You could calculate 15 minutes from the start or the end of the job, depending on your needs.