2015-03-24 08:15:59 -04:00
|
|
|
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)
|
2015-03-24 08:24:35 -04:00
|
|
|
@ref, @format = ref, format.downcase
|
2015-03-24 08:15:59 -04:00
|
|
|
|
|
|
|
repository = project.repository
|
|
|
|
|
|
|
|
repository.clean_old_archives
|
|
|
|
|
2015-03-31 07:37:21 -04:00
|
|
|
return unless file_path
|
2015-03-24 08:15:59 -04:00
|
|
|
return if archived? || archiving?
|
|
|
|
|
2015-03-24 08:24:35 -04:00
|
|
|
repository.archive_repo(ref, storage_path, format)
|
2015-03-24 08:15:59 -04:00
|
|
|
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
|
|
|
|
end
|