From 36ccaca35a7be19498d779a5b781cc4e3f0dede8 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 14 Jun 2016 22:11:21 +0200 Subject: [PATCH] project export archiver --- app/controllers/projects_controller.rb | 4 +--- app/models/project.rb | 9 +++++++++ app/workers/gitlab_project_archive_worker.rb | 9 +++++++++ config/initializers/1_settings.rb | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 app/workers/gitlab_project_archive_worker.rb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9a6d4be2fc8..affc298e0ca 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -266,8 +266,6 @@ class ProjectsController < Projects::ApplicationController end def export_project_path - # TODO: move this, probably to ImportExport and refactor - folder = File.join(Settings.shared['path'], 'tmp/project_exports', @project.path_with_namespace) - Dir.glob("#{folder}/*export.tar.gz").max_by {|f| File.ctime(f)} + Dir.glob("#{@project.export_path}/*export.tar.gz").max_by {|f| File.ctime(f)} end end diff --git a/app/models/project.rb b/app/models/project.rb index 9d7b988bf21..617dbf9a925 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -348,6 +348,11 @@ class Project < ActiveRecord::Base joins(join_body).reorder('join_note_counts.amount DESC') end + + # Deletes gitlab project export files older than 24 hours + def archive_gitlab_exports! + Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -mmin +1440 -delete)) + end end def team @@ -1104,4 +1109,8 @@ class Project < ActiveRecord::Base Rails.logger.error "Export job failed to start for project ID #{self.id}" end end + + def export_path + File.join(ImportExport.storage_path, path_with_namespace) + end end diff --git a/app/workers/gitlab_project_archive_worker.rb b/app/workers/gitlab_project_archive_worker.rb new file mode 100644 index 00000000000..63e7086d41a --- /dev/null +++ b/app/workers/gitlab_project_archive_worker.rb @@ -0,0 +1,9 @@ +class GitlabProjectArchiveWorker + include Sidekiq::Worker + + sidekiq_options queue: :default + + def perform + Project.archive_gitlab_exports! + end +end diff --git a/config/initializers/1_settings.rb b/config/initializers/1_settings.rb index 436751b9d16..64cfc0f5357 100644 --- a/config/initializers/1_settings.rb +++ b/config/initializers/1_settings.rb @@ -288,6 +288,9 @@ Settings.cron_jobs['admin_email_worker']['job_class'] = 'AdminEmailWorker' Settings.cron_jobs['repository_archive_cache_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['repository_archive_cache_worker']['cron'] ||= '0 * * * *' Settings.cron_jobs['repository_archive_cache_worker']['job_class'] = 'RepositoryArchiveCacheWorker' +Settings.cron_jobs['gitlab_project_archive_worker'] ||= Settingslogic.new({}) +Settings.cron_jobs['gitlab_project_archive_worker']['cron'] ||= '0 * * * *' +Settings.cron_jobs['gitlab_project_archive_worker']['job_class'] = 'GitlabProjectArchiveWorker' # # GitLab Shell