1
我已经安装了whenever gem:干净的目录中,只要宝石
我要清理公开目录/上传/ tmp目录上轨3.1每次5分钟我的应用程序的红宝石。
every 5.minutes do
#here go the code for clean the directory tmp
end
我该怎么办?
谢谢!
我已经安装了whenever gem:干净的目录中,只要宝石
我要清理公开目录/上传/ tmp目录上轨3.1每次5分钟我的应用程序的红宝石。
every 5.minutes do
#here go the code for clean the directory tmp
end
我该怎么办?
谢谢!
您可以尝试使用标准库中包含的FileUtils#rm_rf
。例如:
FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*")
编辑
用耙子任务的一种方法可能是(与宝石时使用):
1)创建f.ex rake任务: lib/tasks/cleanup.rake
与类似于以下东西:
require 'fileutils'
namespace :app do
desc "Cleanup temp uploads"
task :cleanup => :environment do
FileUtils.rm_rf Dir.glob("#{Rails.root}/public/uploads/tmp/*")
end
end
2)在config/schedule.rb
(奔跑之后由创建每当克wheneverize命令):
every 5.minutes do
# run the previous app:cleanup task
rake "app:cleanup"
end
3)当只有一个包装很容易地定义crontab作业,所以现在我们需要定义的时间表导出到crontab文件为当前用户。为了做到这一点,我们应该从应用程序根目录键入:
bundle exec whenever -w
4)你可以检查它的工作通过键入crontab -l
和你应该像下面这样:
# Begin Whenever generated tasks for: /tmp/whene/config/schedule.rb
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /tmp/whene && RAILS_ENV=production bundle exec rake app:cleanup --silent
作为一个侧面说明,如果您希望操作写入一些日志输出,请检查this page on the whenever github wiki。
希望它有帮助。
谢谢,但是如何在任何gem代码中部署?再次感谢您:) – hyperrjas 2012-03-08 13:04:44
编辑,以展示如何与时间做到这一点的例子,希望它有所帮助。 – 2012-03-08 13:16:28
谢谢我已经检查过但没有任何反应:(我在ubuntu 10.10 maverick中使用我的开发服务器上的mongrel。我如何检查在开发服务器上工作是否正常?谢谢! – hyperrjas 2012-03-08 14:18:42