debian-mirror-gitlab/app/services/import_export_clean_up_service.rb

34 lines
734 B
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
class ImportExportCleanUpService
LAST_MODIFIED_TIME_IN_MINUTES = 1440
attr_reader :mmin, :path
def initialize(mmin = LAST_MODIFIED_TIME_IN_MINUTES)
@mmin = mmin
@path = Gitlab::ImportExport.storage_path
end
def execute
Gitlab::Metrics.measure(:import_export_clean_up) do
2018-11-08 19:23:39 +05:30
clean_up_export_object_files
break unless File.directory?(path)
2016-08-24 12:49:21 +05:30
clean_up_export_files
end
end
private
def clean_up_export_files
Gitlab::Popen.popen(%W(find #{path} -not -path #{path} -mmin +#{mmin} -delete))
end
2018-11-08 19:23:39 +05:30
def clean_up_export_object_files
ImportExportUpload.where('updated_at < ?', mmin.minutes.ago).each do |upload|
upload.remove_export_file!
upload.save!
end
end
2016-08-24 12:49:21 +05:30
end