summaryrefslogtreecommitdiff
path: root/app/workers/repository_archive_worker.rb
blob: 3f4681a80f4a78dd7f99a20a6b79823ee87bda3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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