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
|
2019-10-01 14:06:28 -04:00
|
|
|
service = Projects::HousekeepingService.new(@project)
|
|
|
|
|
|
|
|
service.execute do
|
2017-09-01 08:01:50 -04:00
|
|
|
repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
|
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!
|
2017-08-25 10:38:07 -04:00
|
|
|
rescue Projects::HousekeepingService::LeaseTaken => e
|
2019-07-10 15:26:47 -04:00
|
|
|
Rails.logger.info( # rubocop:disable Gitlab/RailsLogger
|
2017-08-25 10:38:07 -04:00
|
|
|
"Could not perform housekeeping for project #{@project.full_path} (#{@project.id}): #{e}")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def repository
|
|
|
|
@repository ||= @project.repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|