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