Commit d87e082e authored by Jacob Vosmaer's avatar Jacob Vosmaer Committed by Mayra Cabrera

Remove pages sites asynchronously

parent 3b7d9445
...@@ -21,7 +21,7 @@ class Projects::PagesController < Projects::ApplicationController ...@@ -21,7 +21,7 @@ class Projects::PagesController < Projects::ApplicationController
format.html do format.html do
redirect_to project_pages_path(@project), redirect_to project_pages_path(@project),
status: :found, status: :found,
notice: 'Pages were removed' notice: 'Pages were scheduled for removal'
end end
end end
end end
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
module Pages module Pages
class DeleteService < BaseService class DeleteService < BaseService
def execute def execute
project.remove_pages if Feature.enabled?(:async_pages_removal, project)
project.pages_domains.destroy_all # rubocop: disable Cop/DestroyAll PagesRemoveWorker.perform_async(project.id)
else
PagesRemoveWorker.new.perform(project.id)
end
end end
end end
end end
...@@ -1532,6 +1532,14 @@ ...@@ -1532,6 +1532,14 @@
:weight: 1 :weight: 1
:idempotent: :idempotent:
:tags: [] :tags: []
- :name: pages_remove
:feature_category: :pages
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent:
:tags: []
- :name: pages_update_configuration - :name: pages_update_configuration
:feature_category: :pages :feature_category: :pages
:has_external_dependencies: :has_external_dependencies:
......
# frozen_string_literal: true
class PagesRemoveWorker # rubocop:disable Scalability/IdempotentWorker
include ApplicationWorker
sidekiq_options retry: 3
feature_category :pages
loggable_arguments 0
def perform(project_id)
project = Project.find_by_id(project_id)
return unless project
project.remove_pages
project.pages_domains.delete_all
end
end
---
name: async_pages_removal
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38313
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/239318
group: team::Scalability
type: development
default_enabled: false
\ No newline at end of file
...@@ -178,6 +178,8 @@ ...@@ -178,6 +178,8 @@
- 1 - 1
- - pages_domain_verification - - pages_domain_verification
- 1 - 1
- - pages_remove
- 1
- - pages_update_configuration - - pages_update_configuration
- 1 - 1
- - personal_access_tokens - - personal_access_tokens
......
...@@ -5,7 +5,7 @@ return if Rails.env.production? ...@@ -5,7 +5,7 @@ return if Rails.env.production?
namespace :gitlab do namespace :gitlab do
namespace :sidekiq do namespace :sidekiq do
def write_yaml(path, banner, object) def write_yaml(path, banner, object)
File.write(path, banner + YAML.dump(object)) File.write(path, banner + YAML.dump(object).gsub(/ *$/m, ''))
end end
namespace :all_queues_yml do namespace :all_queues_yml do
......
...@@ -380,14 +380,14 @@ RSpec.shared_examples 'pages settings editing' do ...@@ -380,14 +380,14 @@ RSpec.shared_examples 'pages settings editing' do
expect(project).to be_pages_deployed expect(project).to be_pages_deployed
end end
it 'removes the pages' do it 'removes the pages', :sidekiq_inline do
visit project_pages_path(project) visit project_pages_path(project)
expect(page).to have_link('Remove pages') expect(page).to have_link('Remove pages')
accept_confirm { click_link 'Remove pages' } accept_confirm { click_link 'Remove pages' }
expect(page).to have_content('Pages were removed') expect(page).to have_content('Pages were scheduled for removal')
expect(project.reload.pages_deployed?).to be_falsey expect(project.reload.pages_deployed?).to be_falsey
end end
end end
......
...@@ -39,7 +39,9 @@ RSpec.describe API::Pages do ...@@ -39,7 +39,9 @@ RSpec.describe API::Pages do
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return 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) expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, project.namespace.full_path, anything)
Sidekiq::Testing.inline! do
delete api("/projects/#{project.id}/pages", admin ) delete api("/projects/#{project.id}/pages", admin )
end
expect(project.reload.pages_metadatum.deployed?).to be(false) expect(project.reload.pages_metadatum.deployed?).to be(false)
end end
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Pages::DeleteService do RSpec.describe Pages::DeleteService do
shared_examples 'remove pages' do
let_it_be(:project) { create(:project, path: "my.project")} let_it_be(:project) { create(:project, path: "my.project")}
let_it_be(:admin) { create(:admin) } let_it_be(:admin) { create(:admin) }
let_it_be(:domain) { create(:pages_domain, project: project) } let_it_be(:domain) { create(:pages_domain, project: project) }
...@@ -12,7 +13,7 @@ RSpec.describe Pages::DeleteService do ...@@ -12,7 +13,7 @@ RSpec.describe Pages::DeleteService do
expect_any_instance_of(Gitlab::PagesTransfer).to receive(:rename_project).and_return 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) expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, project.namespace.full_path, anything)
service.execute Sidekiq::Testing.inline! { service.execute }
expect(project.reload.pages_metadatum.deployed?).to be(false) expect(project.reload.pages_metadatum.deployed?).to be(false)
end end
...@@ -20,8 +21,27 @@ RSpec.describe Pages::DeleteService do ...@@ -20,8 +21,27 @@ RSpec.describe Pages::DeleteService do
it 'deletes all domains' do it 'deletes all domains' do
expect(project.pages_domains.count).to be 1 expect(project.pages_domains.count).to be 1
service.execute Sidekiq::Testing.inline! { service.execute }
expect(project.reload.pages_domains.count).to be 0 expect(project.reload.pages_domains.count).to be 0
end end
end
context 'with feature flag disabled' do
before do
stub_feature_flags(async_pages_removal: false)
expect(PagesRemoveWorker).not_to receive(:perform_async)
end
it_behaves_like 'remove pages'
end
context 'with feature flag enabled' do
before do
expect(PagesRemoveWorker).to receive(:perform_async).and_call_original
end
it_behaves_like 'remove pages'
end
end end
# frozen_string_literal: true
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) }
subject { described_class.new.perform(project.id) }
it 'deletes published pages' do
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
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