Commit 75cfe861 authored by Sean McGivern's avatar Sean McGivern

Only schedule PagesTransferWorker when project has pages

If a project has no pages deployed, we don't need to schedule this
worker at all.
parent 0cfccf25
......@@ -97,16 +97,18 @@ module Projects
end
if ::Feature.enabled?(:async_pages_move_project_rename, project)
# Block will be evaluated in the context of project so we need
# to bind to a local variable to capture it, as the instance
# variable and method aren't available on Project
path_before_local = @path_before
project.run_after_commit_or_now do
Gitlab::PagesTransfer
.new
.async
.rename_project(path_before_local, path, namespace.full_path)
if project.pages_deployed?
# Block will be evaluated in the context of project so we need
# to bind to a local variable to capture it, as the instance
# variable and method aren't available on Project
path_before_local = @path_before
project.run_after_commit_or_now do
Gitlab::PagesTransfer
.new
.async
.rename_project(path_before_local, path, namespace.full_path)
end
end
else
Gitlab::PagesTransfer
......
......@@ -75,10 +75,25 @@ RSpec.describe Projects::AfterRenameService do
end
end
it 'schedules a move of the pages directory' do
expect(PagesTransferWorker).to receive(:perform_async).with('rename_project', anything)
context 'when the project has pages deployed' do
it 'schedules a move of the pages directory' do
allow(project).to receive(:pages_deployed?).and_return(true)
service_execute
expect(PagesTransferWorker).to receive(:perform_async).with('rename_project', anything)
service_execute
end
end
context 'when the project does not have pages deployed' do
it 'does nothing with the pages directory' do
allow(project).to receive(:pages_deployed?).and_return(false)
expect(PagesTransferWorker).not_to receive(:perform_async)
expect(Gitlab::PagesTransfer).not_to receive(:new)
service_execute
end
end
end
......@@ -180,10 +195,25 @@ RSpec.describe Projects::AfterRenameService do
end
end
it 'schedules a move of the pages directory' do
expect(PagesTransferWorker).to receive(:perform_async).with('rename_project', anything)
context 'when the project has pages deployed' do
it 'schedules a move of the pages directory' do
allow(project).to receive(:pages_deployed?).and_return(true)
service_execute
expect(PagesTransferWorker).to receive(:perform_async).with('rename_project', anything)
service_execute
end
end
context 'when the project does not have pages deployed' do
it 'does nothing with the pages directory' do
allow(project).to receive(:pages_deployed?).and_return(false)
expect(PagesTransferWorker).not_to receive(:perform_async)
expect(Gitlab::PagesTransfer).not_to receive(:new)
service_execute
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