Commit 3d99ad59 authored by Vladimir Shushlin's avatar Vladimir Shushlin

Remove pages domains synchrously

The only operation which should be performed
asynchrounsly is actual disk operations

marking pages as not deployed doesn't require disk access
and removal of domain also doesn't if pages are
already marked as deployed
parent d7b74a28
......@@ -3,6 +3,9 @@
module Pages
class DeleteService < BaseService
def execute
project.mark_pages_as_not_deployed # prevents domain from updating config when deleted
project.pages_domains.delete_all
PagesRemoveWorker.perform_async(project.id)
end
end
......
......@@ -12,6 +12,5 @@ class PagesRemoveWorker # rubocop:disable Scalability/IdempotentWorker
return unless project
project.remove_pages
project.pages_domains.delete_all
end
end
......@@ -3,25 +3,46 @@
require 'spec_helper'
RSpec.describe Pages::DeleteService do
let_it_be(:project) { create(:project, path: "my.project")}
let_it_be(:admin) { create(:admin) }
let_it_be(:domain) { create(:pages_domain, project: project) }
let_it_be(:service) { described_class.new(project, admin)}
it 'deletes published pages' do
let(:project) { create(:project, path: "my.project")}
let!(:domain) { create(:pages_domain, project: project) }
let(:service) { described_class.new(project, admin)}
before do
project.mark_pages_as_deployed
end
it 'deletes published pages', :sidekiq_inline do
expect(project.pages_deployed?).to be(true)
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return true
expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, project.namespace.full_path, anything)
Sidekiq::Testing.inline! { service.execute }
service.execute
expect(project.reload.pages_metadatum.deployed?).to be(false)
expect(project.pages_deployed?).to be(false)
end
it 'deletes all domains' do
expect(project.pages_domains.count).to be 1
it 'deletes all domains', :sidekiq_inline do
expect(project.pages_domains.count).to eq(1)
service.execute
Sidekiq::Testing.inline! { service.execute }
expect(project.reload.pages_domains.count).to eq(0)
end
it 'marks pages as not deployed, deletes domains and schedules worker to remove pages from disk' do
expect(project.pages_deployed?).to eq(true)
expect(project.pages_domains.count).to eq(1)
service.execute
expect(project.pages_deployed?).to eq(false)
expect(project.pages_domains.count).to eq(0)
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return true
expect(project.reload.pages_domains.count).to be 0
Sidekiq::Worker.drain_all
end
end
......@@ -3,24 +3,23 @@
require 'spec_helper'
RSpec.describe PagesRemoveWorker do
let_it_be(:project) { create(:project, path: "my.project")}
let_it_be(:domain) { create(:pages_domain, project: project) }
let(:project) { create(:project, path: "my.project")}
let!(:domain) { create(:pages_domain, project: project) }
subject { described_class.new.perform(project.id) }
before do
project.mark_pages_as_deployed
end
it 'deletes published pages' do
expect(project.pages_deployed?).to be(true)
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return true
expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, project.namespace.full_path, anything)
subject
expect(project.reload.pages_metadatum.deployed?).to be(false)
end
it 'deletes all domains' do
expect(project.pages_domains.count).to be 1
subject
expect(project.reload.pages_domains.count).to be 0
expect(project.reload.pages_deployed?).to be(false)
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