Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-24 15:15:59 +0300
committerDouwe Maan <douwe@gitlab.com>2015-03-31 13:52:20 +0300
commit2cfd0b59aeb410c1541530ca3eb5f5c472b978e0 (patch)
tree6456eb0d262036234c851dd516f3edd12cc0f833 /app/workers
parent33a8f53f7a8fdc40d0f0ee4245258c8dba99198a (diff)
Archive repositories in background worker.
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/repository_archive_worker.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/workers/repository_archive_worker.rb b/app/workers/repository_archive_worker.rb
new file mode 100644
index 00000000000..3f4681a80f4
--- /dev/null
+++ b/app/workers/repository_archive_worker.rb
@@ -0,0 +1,46 @@
+class RepositoryArchiveWorker
+ include Sidekiq::Worker
+
+ sidekiq_options queue: :archive_repo
+
+ attr_accessor :project, :ref, :format
+
+ def perform(project_id, ref, format)
+ @project = Project.find(project_id)
+ @ref, @format = ref, format
+
+ repository = project.repository
+
+ repository.clean_old_archives
+
+ return if archived? || archiving?
+
+ repository.archive_repo(*archive_args)
+ end
+
+ private
+
+ def storage_path
+ Gitlab.config.gitlab.repository_downloads_path
+ end
+
+ def archive_args
+ @archive_args ||= [ref, storage_path, format.downcase]
+ end
+
+ def file_path
+ @file_path ||= project.repository.archive_file_path(*archive_args)
+ end
+
+ def pid_file_path
+ @pid_file_path ||= project.repository.archive_pid_file_path(*archive_args)
+ end
+
+ def archived?
+ File.exist?(file_path)
+ end
+
+ def archiving?
+ File.exist?(pid_file_path)
+ end
+end