diff --git a/lib/tasks/attachment_maintaining_service.rake b/lib/tasks/attachment_maintaining_service.rake new file mode 100644 index 0000000000000000000000000000000000000000..6587edd4c8c5d01ee8f47c379fdbe34b4b06925d --- /dev/null +++ b/lib/tasks/attachment_maintaining_service.rake @@ -0,0 +1,25 @@ +require 'fileutils' + + namespace :attachment_maintaining_service do + desc 'Removing 10 attachments' + task remove_attachments: :environment do + m = sort_directories.first(10) + m.each do |mm| + #puts (mm) + FileUtils.rm_r(mm) + end + end + + def sort_directories + files_sorted_by_time = Dir[dir_path].sort_by{ |f| File.atime(f) } + files_sorted_by_time + end + + private + + def dir_path + c = Rails.root.join('public','attachments','*').to_s + c + end + + end