GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit 932d3251 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Move to Projects::HousecleaningService

parent 5c31c720
......@@ -372,7 +372,7 @@ def self.with_feature_available_for_user(feature, user)
if Gitlab::ImportSources.importer_names.include?(project.import_type) && project.repo_exists?
project.run_after_commit do
begin
Projects::ImportExport::CleanupService.new(project).execute
Projects::HousecleaningService.new(project).execute
rescue Projects::HousekeepingService::LeaseTaken => e
Rails.logger.info("Could not perform housekeeping for project #{project.full_path} (#{project.id}): #{e}")
end
......
module Projects
class HousecleaningService
def self.reserved_refs_names
%w[heads tags merge-requests keep-around environments]
end
def self.reserved_refs_regexp
names = reserved_refs_names.map(&Regexp.method(:escape)).join('|')
%r{\Arefs/(?:#{names})/}
end
def initialize(project)
@project = project
end
# This could raise Projects::HousekeepingService::LeaseTaken
def execute
Projects::HousekeepingService.new(@project).execute do
garbage_refs.each(&rugged.references.method(:delete))
end
end
private
def garbage_refs
@garbage_refs ||= begin
reserved_refs_regexp = self.class.reserved_refs_regexp
rugged.references.reject do |ref|
ref.name =~ reserved_refs_regexp
end
end
end
def rugged
@rugged ||= @project.repository.rugged
end
end
end
module Projects
module ImportExport
class CleanupService
def self.reserved_refs_names
%w[heads tags merge-requests keep-around environments]
end
def self.reserved_refs_regexp
names = reserved_refs_names.map(&Regexp.method(:escape)).join('|')
%r{\Arefs/(?:#{names})/}
end
def initialize(project)
@project = project
end
# This could raise Projects::HousekeepingService::LeaseTaken
def execute
Projects::HousekeepingService.new(@project).execute do
garbage_refs.each(&rugged.references.method(:delete))
end
end
private
def garbage_refs
@garbage_refs ||= begin
reserved_refs_regexp = self.class.reserved_refs_regexp
rugged.references.reject do |ref|
ref.name =~ reserved_refs_regexp
end
end
end
def rugged
@rugged ||= @project.repository.rugged
end
end
end
end
......@@ -1563,14 +1563,14 @@ def create_pipeline
describe 'project import state transitions' do
context 'state transition: [:started] => [:finished]' do
let(:cleanup_service) { spy(:cleanup_service) }
let(:housecleaning_service) { spy(:housecleaning_service) }
let(:housekeeping_service) { spy(:housekeeping_service) }
before do
allow(Projects::ImportExport::CleanupService)
.to receive(:new) { cleanup_service }
allow(Projects::HousecleaningService)
.to receive(:new) { housecleaning_service }
allow(cleanup_service)
allow(housecleaning_service)
.to receive(:execute) { housekeeping_service.execute }
allow(Projects::HousekeepingService)
......@@ -1589,7 +1589,7 @@ def create_pipeline
project.import_finish
expect(cleanup_service).to have_received(:execute)
expect(housecleaning_service).to have_received(:execute)
expect(housekeeping_service).to have_received(:execute)
end
......
require 'spec_helper'
describe Projects::ImportExport::CleanupService do
describe Projects::HousecleaningService do
subject { described_class.new(project) }
let(:project) { create(:project, :repository) }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment