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
|
2021-03-08 18:12:59 +05:30
|
|
|
service = Repositories::HousekeepingService.new(@project)
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
service.execute do
|
2020-03-13 15:44:24 +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!
|
2021-03-08 18:12:59 +05:30
|
|
|
rescue Repositories::HousekeepingService::LeaseTaken => e
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Import::Logger.info(
|
|
|
|
message: 'Project housekeeping failed',
|
|
|
|
project_full_path: @project.full_path,
|
|
|
|
project_id: @project.id,
|
2020-07-28 23:09:34 +05:30
|
|
|
'error.message' => e.message
|
2020-06-23 00:09:42 +05:30
|
|
|
)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def import_failure_service
|
|
|
|
Gitlab::ImportExport::ImportFailureService.new(@project)
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def repository
|
2020-03-13 15:44:24 +05:30
|
|
|
@project.repository
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|