summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-24 13:15:59 +0100
committerDouwe Maan <douwe@gitlab.com>2015-03-31 12:52:20 +0200
commit2cfd0b59aeb410c1541530ca3eb5f5c472b978e0 (patch)
tree6456eb0d262036234c851dd516f3edd12cc0f833 /app/services
parent33a8f53f7a8fdc40d0f0ee4245258c8dba99198a (diff)
downloadgitlab-ce-2cfd0b59aeb410c1541530ca3eb5f5c472b978e0.tar.gz
Archive repositories in background worker.
Diffstat (limited to 'app/services')
-rw-r--r--app/services/archive_repository_service.rb67
1 files changed, 59 insertions, 8 deletions
diff --git a/app/services/archive_repository_service.rb b/app/services/archive_repository_service.rb
index 8823f6fdc67..cb2026fedba 100644
--- a/app/services/archive_repository_service.rb
+++ b/app/services/archive_repository_service.rb
@@ -1,14 +1,65 @@
class ArchiveRepositoryService
- def execute(project, ref, format)
- storage_path = Gitlab.config.gitlab.repository_downloads_path
+ attr_reader :project, :ref, :format
- unless File.directory?(storage_path)
- FileUtils.mkdir_p(storage_path)
+ def initialize(project, ref, format)
+ format ||= 'tar.gz'
+ @project, @ref, @format = project, ref, format
+ end
+
+ def execute
+ project.repository.clean_old_archives
+
+ raise "No archive file path" unless file_path
+
+ return file_path if archived?
+
+ unless archiving?
+ RepositoryArchiveWorker.perform_async(project.id, ref, format)
end
- format ||= 'tar.gz'
- repository = project.repository
- repository.clean_old_archives
- repository.archive_repo(ref, storage_path, format.downcase)
+ archived = wait_until_archived
+
+ file_path if archived
+ 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
+
+ def wait_until_archived
+ timeout = 5.0
+ t1 = Time.now
+
+ begin
+ sleep 0.1
+
+ success = archived?
+
+ t2 = Time.now
+ end until success || t2 - t1 >= timeout
+
+ success
end
end