我有一个耙子任务,每隔几个小时就会更改首页上的数据。我已经测试过了,它在开发中可以正常工作。但它在生产中不起作用。我需要做些什么才能获得我想要看到的更改?我应该添加一个重新启动服务器的命令吗?这会使服务器确认更改吗?有没有更聪明的方法来做到这一点?Rake任务在开发中工作,但不在生产中
耙子任务如下。它将由heroku的调度程序添加运行,所以它现在位于lib/tasks/scheduler.rake文件中。
desc 'changes the meta tags'
task :mixup_meta_tags => :environment do
regex = /@meta_tag/
file = File.open('app/controllers/site_controller.rb', 'r')
lines = []
file.each_line do |line|
(line =~ regex) ? (lines << replace_line(line)) : (lines << line)
end
file.close
file = File.open('app/controllers/site_controller.rb', 'w')
lines.each{|line| file.write line}
file.close
end
def replace_line(line)
meta_tags = MetaTag.all.map { |tag| tag["tag"] }
new_tag = meta_tags.sample(1)[0]
line = " @meta_tag = \"#{new_tag}\" \n" # added the newline
end
更确切地说...首先发布你的rake任务代码,以及如何运行它。您不应该重新启动服务器来运行任务。 – 2012-07-26 11:56:23
没问题。刚添加rake任务发布。 – 2012-07-26 12:39:58