clean up exports weekly

This commit is contained in:
Arpit Jalan 2014-08-15 01:47:52 +05:30
parent d0736a06b6
commit b0f44dcdf3
2 changed files with 10 additions and 0 deletions

View File

@ -11,6 +11,7 @@ module Jobs
Post.calculate_avg_time
Topic.calculate_avg_time
ScoreCalculator.new.calculate
ExportCsv.remove_old_exports # delete exported CSV files older than 2 days
end
end
end

View File

@ -9,6 +9,15 @@ class ExportCsv
end
end
def self.remove_old_exports
dir = Dir.new(ExportCsv.base_directory)
dir.each do |file|
if (File.mtime(File.join(ExportCsv.base_directory, file)) < 2.days.ago)
File.delete(File.join(ExportCsv.base_directory, file))
end
end
end
def self.base_directory
File.join(Rails.root, "public", "uploads", "csv_exports", RailsMultisite::ConnectionManagement.current_db)
end