mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
Adds a rake task, and a task to whenevers schedule, to delete all zips in public/data/zip older than 2 days
This commit is contained in:
@@ -22,3 +22,7 @@
|
||||
every :day, at: '1am' do
|
||||
rake 'dump:full', environment: 'production'
|
||||
end
|
||||
|
||||
every 7.days, at: '1am' do
|
||||
rake 'dump:clean', environment: 'production'
|
||||
end
|
||||
|
||||
22
lib/tasks/dump_clean.rake
Normal file
22
lib/tasks/dump_clean.rake
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace :dump do
|
||||
desc 'clean everything in public/zip older than 2 days'
|
||||
task clean: :environment do
|
||||
dir = File.join(Rails.root, 'public/data/zip')
|
||||
# Don't ever delete the link and what is linked to
|
||||
datadump = File.join(dir, 'opensnp_datadump.current.zip')
|
||||
forbidden_files = [datadump]
|
||||
forbidden_files << File.readlink(datadump) unless not File.file? datadump
|
||||
|
||||
Dir.entries(dir).each do |f|
|
||||
f = File.join(dir, f)
|
||||
# Has to be older than 2 days, don't delete important files, only delete archives
|
||||
if (get_file_age_in_days(f) > 2) and (not forbidden_files.include? f) and (f.ends_with? 'zip')
|
||||
File.delete(f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_file_age_in_days(file)
|
||||
(Time.now - File.mtime(file)) / (60 * 60 * 24)
|
||||
end
|
||||
Reference in New Issue
Block a user