2014-08-13 14:28:22 -04:00
|
|
|
class ArchiveRepositoryService
|
2015-03-24 08:15:59 -04:00
|
|
|
attr_reader :project, :ref, :format
|
2014-08-13 14:28:22 -04:00
|
|
|
|
2015-03-24 08:15:59 -04:00
|
|
|
def initialize(project, ref, format)
|
|
|
|
format ||= 'tar.gz'
|
2015-03-24 08:24:35 -04:00
|
|
|
@project, @ref, @format = project, ref, format.downcase
|
2015-03-24 08:15:59 -04:00
|
|
|
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)
|
2014-08-13 14:28:22 -04:00
|
|
|
end
|
|
|
|
|
2015-03-24 08:15:59 -04:00
|
|
|
archived = wait_until_archived
|
|
|
|
|
|
|
|
file_path if archived
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def storage_path
|
|
|
|
Gitlab.config.gitlab.repository_downloads_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_path
|
2015-03-24 08:24:35 -04:00
|
|
|
@file_path ||= project.repository.archive_file_path(ref, storage_path, format)
|
2015-03-24 08:15:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def pid_file_path
|
2015-03-24 08:24:35 -04:00
|
|
|
@pid_file_path ||= project.repository.archive_pid_file_path(ref, storage_path, format)
|
2015-03-24 08:15:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def archived?
|
|
|
|
File.exist?(file_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def archiving?
|
|
|
|
File.exist?(pid_file_path)
|
|
|
|
end
|
|
|
|
|
2015-03-24 08:24:35 -04:00
|
|
|
def wait_until_archived(timeout = 5.0)
|
2015-03-24 08:15:59 -04:00
|
|
|
t1 = Time.now
|
|
|
|
|
|
|
|
begin
|
|
|
|
sleep 0.1
|
|
|
|
|
|
|
|
success = archived?
|
|
|
|
|
|
|
|
t2 = Time.now
|
|
|
|
end until success || t2 - t1 >= timeout
|
|
|
|
|
|
|
|
success
|
2014-08-13 14:28:22 -04:00
|
|
|
end
|
|
|
|
end
|