Ruby on rails 什么';每小时在heroku上运行cron作业的语法是什么?

Ruby on rails 什么';每小时在heroku上运行cron作业的语法是什么?,ruby-on-rails,cron,heroku,jobs,Ruby On Rails,Cron,Heroku,Jobs,我刚刚获得了Heroku的cron的付费版本,以便每小时运行一些任务。我想知道的是,我应该使用什么语法来让它每小时运行一次。到目前为止,我有这个,你能告诉我它是否正确吗: desc "Tasks called by the Heroku cron add-on" task :cron => :environment do if Time.now.hour % 1 == 0 # run every sixty minutes? puts "Updating view count

我刚刚获得了Heroku的cron的付费版本,以便每小时运行一些任务。我想知道的是,我应该使用什么语法来让它每小时运行一次。到目前为止,我有这个,你能告诉我它是否正确吗:

desc "Tasks called by the Heroku cron add-on"
task :cron => :environment do
  if Time.now.hour % 1 == 0 # run every sixty minutes?

    puts "Updating view counts...."
    Video.update_view_counts  
    puts "Finished....."

    puts "Updating video scores...."
    VideoPost.update_score_caches
    puts "Finished....."

    puts "Erasing videos....."
    Video.erase_videos!
    puts "Finished....."

  end

  if Time.now.hour == 0 # run at midnight

  end
end
我需要知道这条带有1的线是否正确

if Time.now.hour % 1 == 0
提前感谢您的帮助


致以最诚挚的问候。

如果您想每小时跑步,请不要费心检查。Heroku会每小时运行一次

由于%1将始终返回0,因此最好只返回:

desc "Tasks called by the Heroku cron add-on"
task :cron => :environment do
  puts "Updating view counts...."
  Video.update_view_counts  
  puts "Finished....."
  #...

  if Time.now.hour == 1 #1am
    #...
  end

end
此外,如果您希望能够在需要时运行Video.update\u view\u counts,您可以(在创建rake任务之后):


这样,您就可以在cron内部运行它,如果需要,可以手动运行

如果您想每小时运行一次,就不用麻烦检查了。Heroku会每小时运行一次

由于%1将始终返回0,因此最好只返回:

desc "Tasks called by the Heroku cron add-on"
task :cron => :environment do
  puts "Updating view counts...."
  Video.update_view_counts  
  puts "Finished....."
  #...

  if Time.now.hour == 1 #1am
    #...
  end

end
此外,如果您希望能够在需要时运行Video.update\u view\u counts,您可以(在创建rake任务之后):


这样,您就可以在cron内部运行它,如果需要,还可以手动运行它

,因为您已经有了每小时一次的cron,您不必检查运行代码的时间

task :cron => :environment do

    #<--- hourly cron begins 
    puts "Updating view counts...."
    Video.update_view_counts  
    puts "Finished....."

    puts "Updating video scores...."
    VideoPost.update_score_caches
    puts "Finished....."

    puts "Erasing videos....."
    Video.erase_videos!
    puts "Finished....."
    #hourly cron ends  --->

    if Time.now.hour == 0 # run at midnight

    end  

end
task:cron=>:environment do
#
如果Time.now.hour==0,则在午夜运行
结束
结束

因为您已经有了每小时一次的cron,所以不必检查运行代码的时间

task :cron => :environment do

    #<--- hourly cron begins 
    puts "Updating view counts...."
    Video.update_view_counts  
    puts "Finished....."

    puts "Updating video scores...."
    VideoPost.update_score_caches
    puts "Finished....."

    puts "Erasing videos....."
    Video.erase_videos!
    puts "Finished....."
    #hourly cron ends  --->

    if Time.now.hour == 0 # run at midnight

    end  

end
task:cron=>:environment do
#
如果Time.now.hour==0,则在午夜运行
结束
结束