Commit 53c37b9b authored by Vladimir Shushlin's avatar Vladimir Shushlin

Shchedule pages deployments removal from pages delete service

Currently we schedule removal worker, it then calls
`#remove_pages`, which schedules deployments removal

We can just move removal scheduling to the first service
parent 3d99ad59
...@@ -1789,6 +1789,7 @@ class Project < ApplicationRecord ...@@ -1789,6 +1789,7 @@ class Project < ApplicationRecord
end end
# TODO: what to do here when not using Legacy Storage? Do we still need to rename and delay removal? # TODO: what to do here when not using Legacy Storage? Do we still need to rename and delay removal?
# answer: we should just remove all of this
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def remove_pages def remove_pages
# Projects with a missing namespace cannot have their pages removed # Projects with a missing namespace cannot have their pages removed
...@@ -1796,8 +1797,6 @@ class Project < ApplicationRecord ...@@ -1796,8 +1797,6 @@ class Project < ApplicationRecord
mark_pages_as_not_deployed unless destroyed? mark_pages_as_not_deployed unless destroyed?
DestroyPagesDeploymentsWorker.perform_async(id)
# 1. We rename pages to temporary directory # 1. We rename pages to temporary directory
# 2. We wait 5 minutes, due to NFS caching # 2. We wait 5 minutes, due to NFS caching
# 3. We asynchronously remove pages with force # 3. We asynchronously remove pages with force
......
...@@ -6,6 +6,8 @@ module Pages ...@@ -6,6 +6,8 @@ module Pages
project.mark_pages_as_not_deployed # prevents domain from updating config when deleted project.mark_pages_as_not_deployed # prevents domain from updating config when deleted
project.pages_domains.delete_all project.pages_domains.delete_all
DestroyPagesDeploymentsWorker.perform_async(project.id)
PagesRemoveWorker.perform_async(project.id) PagesRemoveWorker.perform_async(project.id)
end end
end end
......
...@@ -4144,27 +4144,6 @@ RSpec.describe Project, factory_default: :keep do ...@@ -4144,27 +4144,6 @@ RSpec.describe Project, factory_default: :keep do
expect { project.destroy }.not_to raise_error expect { project.destroy }.not_to raise_error
end end
context 'when there is an old pages deployment' do
let!(:old_deployment_from_another_project) { create(:pages_deployment) }
let!(:old_deployment) { create(:pages_deployment, project: project) }
it 'schedules a destruction of pages deployments' do
expect(DestroyPagesDeploymentsWorker).to(
receive(:perform_async).with(project.id)
)
project.remove_pages
end
it 'removes pages deployments', :sidekiq_inline do
expect do
project.remove_pages
end.to change { PagesDeployment.count }.by(-1)
expect(PagesDeployment.find_by_id(old_deployment.id)).to be_nil
end
end
end end
describe '#remove_export' do describe '#remove_export' do
......
...@@ -32,6 +32,22 @@ RSpec.describe Pages::DeleteService do ...@@ -32,6 +32,22 @@ RSpec.describe Pages::DeleteService do
expect(project.reload.pages_domains.count).to eq(0) expect(project.reload.pages_domains.count).to eq(0)
end end
it 'schedules a destruction of pages deployments' do
expect(DestroyPagesDeploymentsWorker).to(
receive(:perform_async).with(project.id)
)
service.execute
end
it 'removes pages deployments', :sidekiq_inline do
create(:pages_deployment, project: project)
expect do
service.execute
end.to change { PagesDeployment.count }.by(-1)
end
it 'marks pages as not deployed, deletes domains and schedules worker to remove pages from disk' do 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_deployed?).to eq(true)
expect(project.pages_domains.count).to eq(1) expect(project.pages_domains.count).to eq(1)
......
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