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
|
2018-03-17 18:26:18 +05:30
|
|
|
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
|
|
|
|
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
|
|
|
|
|
|
|
|
def repository
|
|
|
|
@repository ||= @project.repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|