2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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
|
2019-12-21 20:55:43 +05:30
|
|
|
service = Projects::HousekeepingService.new(@project)
|
|
|
|
|
|
|
|
service.execute do
|
2020-03-09 13:42:32 +05:30
|
|
|
import_failure_service.with_retry(action: 'delete_all_refs') do
|
|
|
|
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
# 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!
|
2018-03-17 18:26:18 +05:30
|
|
|
rescue Projects::HousekeepingService::LeaseTaken => e
|
2019-09-30 21:07:59 +05:30
|
|
|
Rails.logger.info( # rubocop:disable Gitlab/RailsLogger
|
2018-03-17 18:26:18 +05:30
|
|
|
"Could not perform housekeeping for project #{@project.full_path} (#{@project.id}): #{e}")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
def import_failure_service
|
|
|
|
Gitlab::ImportExport::ImportFailureService.new(@project)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def repository
|
2020-03-09 13:42:32 +05:30
|
|
|
@project.repository
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|