Commit 312c906c authored by Bob Van Landuyt's avatar Bob Van Landuyt

Update pages config async when updating domain

This makes the update to the pages config file async when updating a
pages domain.

This also skips the update if pages aren't deployed, since in that
case, there would be no config file on disk to update.
parent e1724883
......@@ -3,6 +3,7 @@
class PagesDomain < ApplicationRecord
include Presentable
include FromUnion
include AfterCommitQueue
VERIFICATION_KEY = 'gitlab-pages-verification-code'
VERIFICATION_THRESHOLD = 3.days.freeze
......@@ -222,6 +223,8 @@ class PagesDomain < ApplicationRecord
private
def pages_deployed?
return false unless project
# TODO: remove once `pages_metadatum` is migrated
# https://gitlab.com/gitlab-org/gitlab/issues/33106
unless project.pages_metadatum
......@@ -244,8 +247,13 @@ class PagesDomain < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass
def update_daemon
return if usage_serverless?
return unless pages_deployed?
::Projects::UpdatePagesConfigurationService.new(project).execute
if Feature.enabled?(:async_update_pages_config, project)
run_after_commit { PagesUpdateConfigurationWorker.perform_async(project_id) }
else
Projects::UpdatePagesConfigurationService.new(project).execute
end
end
# rubocop: enable CodeReuse/ServiceClass
......
......@@ -328,9 +328,11 @@ RSpec.describe PagesDomain do
end
describe '#update_daemon' do
let_it_be(:project) { create(:project).tap(&:mark_pages_as_deployed) }
context 'when usage is serverless' do
it 'does not call the UpdatePagesConfigurationService' do
expect(Projects::UpdatePagesConfigurationService).not_to receive(:new)
expect(PagesUpdateConfigurationWorker).not_to receive(:perform_async)
create(:pages_domain, usage: :serverless)
end
......@@ -352,12 +354,30 @@ RSpec.describe PagesDomain do
domain.destroy!
end
it 'delegates to Projects::UpdatePagesConfigurationService' do
it 'delegates to Projects::UpdatePagesConfigurationService when not running async' do
stub_feature_flags(async_update_pages_config: false)
service = instance_double('Projects::UpdatePagesConfigurationService')
expect(Projects::UpdatePagesConfigurationService).to receive(:new) { service }
expect(service).to receive(:execute)
create(:pages_domain)
create(:pages_domain, project: project)
end
it "schedules a PagesUpdateConfigurationWorker" do
expect(PagesUpdateConfigurationWorker).to receive(:perform_async).with(project.id)
create(:pages_domain, project: project)
end
context "when the pages aren't deployed" do
let_it_be(:project) { create(:project).tap(&:mark_pages_as_not_deployed) }
it "does not schedule a PagesUpdateConfigurationWorker" do
expect(PagesUpdateConfigurationWorker).not_to receive(:perform_async).with(project.id)
create(:pages_domain, project: project)
end
end
context 'configuration updates when attributes change' do
......
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