2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-25 10:38:07 -04:00
|
|
|
module Projects
|
|
|
|
class AfterImportService
|
2017-09-01 08:01:50 -04:00
|
|
|
RESERVED_REF_PREFIXES = Repository::RESERVED_REFS_NAMES.map { |n| File.join('refs', n, '/') }
|
2017-08-25 10:38:07 -04:00
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2021-01-19 04:10:32 -05:00
|
|
|
service = Repositories::HousekeepingService.new(@project)
|
2019-10-01 14:06:28 -04:00
|
|
|
|
|
|
|
service.execute do
|
2020-01-31 07:08:33 -05:00
|
|
|
import_failure_service.with_retry(action: 'delete_all_refs') do
|
|
|
|
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
|
|
|
|
end
|
2017-08-25 10:38:07 -04:00
|
|
|
end
|
2019-10-01 14:06:28 -04:00
|
|
|
|
|
|
|
# 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-01-19 04:10:32 -05:00
|
|
|
rescue Repositories::HousekeepingService::LeaseTaken => e
|
2020-05-25 11:07:58 -04:00
|
|
|
Gitlab::Import::Logger.info(
|
|
|
|
message: 'Project housekeeping failed',
|
|
|
|
project_full_path: @project.full_path,
|
|
|
|
project_id: @project.id,
|
2020-07-07 02:09:06 -04:00
|
|
|
'error.message' => e.message
|
2020-05-25 11:07:58 -04:00
|
|
|
)
|
2017-08-25 10:38:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-31 07:08:33 -05:00
|
|
|
def import_failure_service
|
2020-02-03 16:09:00 -05:00
|
|
|
Gitlab::ImportExport::ImportFailureService.new(@project)
|
2020-01-31 07:08:33 -05:00
|
|
|
end
|
|
|
|
|
2017-08-25 10:38:07 -04:00
|
|
|
def repository
|
2020-02-03 16:09:00 -05:00
|
|
|
@project.repository
|
2017-08-25 10:38:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|