Commit ff048ba8 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fix-34417' into 'master'

Perform housekeeping only when an import of a fresh project is completed

Closes #34417

See merge request !12529
parents e3a6fedb 639639ef
......@@ -351,7 +351,16 @@ class Project < ActiveRecord::Base
after_transition started: :finished do |project, _|
project.reset_cache_and_import_attrs
project.perform_housekeeping
if Gitlab::ImportSources.importer_names.include?(project.import_type) && project.repo_exists?
project.run_after_commit do
begin
Projects::HousekeepingService.new(project).execute
rescue Projects::HousekeepingService::LeaseTaken => e
Rails.logger.info("Could not perform housekeeping for project #{project.path_with_namespace} (#{project.id}): #{e}")
end
end
end
end
end
......@@ -509,22 +518,6 @@ class Project < ActiveRecord::Base
ProjectCacheWorker.perform_async(self.id)
end
remove_import_data
end
def perform_housekeeping
return unless repo_exists?
run_after_commit do
begin
Projects::HousekeepingService.new(self).execute
rescue Projects::HousekeepingService::LeaseTaken => e
Rails.logger.info("Could not perform housekeeping for project #{self.path_with_namespace} (#{self.id}): #{e}")
end
end
end
def remove_import_data
import_data&.destroy
end
......
---
title: Perform housekeeping only when an import of a fresh project is completed
merge_request:
author:
......@@ -1500,6 +1500,40 @@ describe Project, models: true do
end
end
describe 'project import state transitions' do
context 'state transition: [:started] => [:finished]' do
let(:housekeeping_service) { spy }
before do
allow(Projects::HousekeepingService).to receive(:new) { housekeeping_service }
end
it 'performs housekeeping when an import of a fresh project is completed' do
project = create(:project_empty_repo, :import_started, import_type: :github)
project.import_finish
expect(housekeeping_service).to have_received(:execute)
end
it 'does not perform housekeeping when project repository does not exist' do
project = create(:empty_project, :import_started, import_type: :github)
project.import_finish
expect(housekeeping_service).not_to have_received(:execute)
end
it 'does not perform housekeeping when project does not have a valid import type' do
project = create(:empty_project, :import_started, import_type: nil)
project.import_finish
expect(housekeeping_service).not_to have_received(:execute)
end
end
end
describe '#latest_successful_builds_for' do
def create_pipeline(status = 'success')
create(:ci_pipeline, project: project,
......
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