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

after_import_service.rb « projects « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb0d084d191fed14fd37820e15601e507c259d1c (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
# frozen_string_literal: true

module Projects
  class AfterImportService
    RESERVED_REF_PREFIXES = Repository::RESERVED_REFS_NAMES.map { |n| File.join('refs', n, '/') }

    def initialize(project)
      @project = project
    end

    def execute
      service = Repositories::HousekeepingService.new(@project)

      service.execute do
        import_failure_service.with_retry(action: 'delete_all_refs') do
          repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
        end
      end

      # Right now we don't actually have a way to know if a project
      # import actually changed, so we increment the counter to avoid
      # causing GC to run every time.
      service.increment!
    rescue Repositories::HousekeepingService::LeaseTaken => e
      Gitlab::Import::Logger.info(
        message: 'Project housekeeping failed',
        project_full_path: @project.full_path,
        project_id: @project.id,
        'error.message' => e.message
      )
    end

    private

    def import_failure_service
      Gitlab::ImportExport::ImportFailureService.new(@project)
    end

    def repository
      @project.repository
    end
  end
end