Commit ba9bb272 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/mirror-import' into 'master'

Fix repository mirror updates for new imports stuck in started

We were calling `RepositoryUpdateMirrorWorker` that sets the import status to `finished` and then add the import job. Then `update_mirror` didn't do anything but set the `import_status` to started. This should be now getting called in the right order... 

Closes https://gitlab.com/gitlab-com/operations/issues/287 and https://gitlab.com/gitlab-org/gitlab-ce/issues/17747

See merge request !416
parents 0f4cf609 d65159e8
Please view this file on the master branch, on stable branches it's out of date.
v 8.8.2
- Fix repository mirror updates for new imports stuck in started
v 8.8.1
- No EE-specific changes
......
......@@ -379,14 +379,6 @@ class Project < ActiveRecord::Base
end
def add_import_job
if repository_exists?
if mirror?
RepositoryUpdateMirrorWorker.perform_async(self.id)
end
return
end
if forked?
job_id = RepositoryForkWorker.perform_async(self.id, forked_from_project.path_with_namespace, self.namespace.path)
else
......@@ -500,7 +492,7 @@ class Project < ActiveRecord::Base
end
def update_mirror
return unless mirror?
return unless mirror? && repository_exists?
return if import_in_progress?
......@@ -509,6 +501,8 @@ class Project < ActiveRecord::Base
else
import_start
end
RepositoryUpdateMirrorWorker.perform_async(self.id)
end
def mark_import_as_failed(error_message)
......
......@@ -955,4 +955,37 @@ describe Project, models: true do
it { is_expected.to be_falsey }
end
end
describe 'Project import job' do
let(:project) { create(:empty_project) }
let(:mirror) { false }
before do
allow_any_instance_of(Gitlab::Shell).to receive(:import_repository).with(project.path_with_namespace, project.import_url).and_return(true)
allow(project).to receive(:repository_exists?).and_return(true)
end
it 'imports a project' do
expect_any_instance_of(RepositoryImportWorker).to receive(:perform).and_call_original
project.import_start
project.add_import_job
expect(project.reload.import_status).to eq('finished')
end
it 'imports a mirrored project' do
allow_any_instance_of(RepositoryUpdateMirrorWorker).to receive(:perform)
expect_any_instance_of(RepositoryImportWorker).to receive(:perform).and_call_original
project.import_start
project.mirror = true
project.add_import_job
expect(project.reload.import_status).to eq('finished')
end
end
end
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