From b0f44dcdf36225eb8687e7e9f907fdca88f4a199 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 15 Aug 2014 01:47:52 +0530 Subject: [PATCH] clean up exports weekly --- app/jobs/scheduled/weekly.rb | 1 + app/models/export_csv.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/app/jobs/scheduled/weekly.rb b/app/jobs/scheduled/weekly.rb index 156cfd74e45..9a079efb05e 100644 --- a/app/jobs/scheduled/weekly.rb +++ b/app/jobs/scheduled/weekly.rb @@ -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 diff --git a/app/models/export_csv.rb b/app/models/export_csv.rb index 214d650de55..ffebf6c1eee 100644 --- a/app/models/export_csv.rb +++ b/app/models/export_csv.rb @@ -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