Commit 39f44c42 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'bvl-async-pages-domain-updates' into 'master'

Update pages config async when updating domain

See merge request gitlab-org/gitlab!39314
parents 6d0fe4ba 312c906c
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
class PagesDomain < ApplicationRecord class PagesDomain < ApplicationRecord
include Presentable include Presentable
include FromUnion include FromUnion
include AfterCommitQueue
VERIFICATION_KEY = 'gitlab-pages-verification-code' VERIFICATION_KEY = 'gitlab-pages-verification-code'
VERIFICATION_THRESHOLD = 3.days.freeze VERIFICATION_THRESHOLD = 3.days.freeze
...@@ -222,6 +223,8 @@ class PagesDomain < ApplicationRecord ...@@ -222,6 +223,8 @@ class PagesDomain < ApplicationRecord
private private
def pages_deployed? def pages_deployed?
return false unless project
# TODO: remove once `pages_metadatum` is migrated # TODO: remove once `pages_metadatum` is migrated
# https://gitlab.com/gitlab-org/gitlab/issues/33106 # https://gitlab.com/gitlab-org/gitlab/issues/33106
unless project.pages_metadatum unless project.pages_metadatum
...@@ -244,8 +247,13 @@ class PagesDomain < ApplicationRecord ...@@ -244,8 +247,13 @@ class PagesDomain < ApplicationRecord
# rubocop: disable CodeReuse/ServiceClass # rubocop: disable CodeReuse/ServiceClass
def update_daemon def update_daemon
return if usage_serverless? 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 end
# rubocop: enable CodeReuse/ServiceClass # rubocop: enable CodeReuse/ServiceClass
......
...@@ -328,9 +328,11 @@ RSpec.describe PagesDomain do ...@@ -328,9 +328,11 @@ RSpec.describe PagesDomain do
end end
describe '#update_daemon' do describe '#update_daemon' do
let_it_be(:project) { create(:project).tap(&:mark_pages_as_deployed) }
context 'when usage is serverless' do context 'when usage is serverless' do
it 'does not call the UpdatePagesConfigurationService' 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) create(:pages_domain, usage: :serverless)
end end
...@@ -352,12 +354,30 @@ RSpec.describe PagesDomain do ...@@ -352,12 +354,30 @@ RSpec.describe PagesDomain do
domain.destroy! domain.destroy!
end 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') service = instance_double('Projects::UpdatePagesConfigurationService')
expect(Projects::UpdatePagesConfigurationService).to receive(:new) { service } expect(Projects::UpdatePagesConfigurationService).to receive(:new) { service }
expect(service).to receive(:execute) 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 end
context 'configuration updates when attributes change' do 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