Commit 192d4e52 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Only update pages config if pages are deployed

The pages config is a file inside the path on the shared NFS. The
directory into which this file is written is created when pages are
deployed and the artifacts are extracted.

If this path has been removed, or hasn't been created yet, we don't
need to update configuration.

Updating the configuration is also a step in the deployment of
pages. So the first deploy, the configuration would be written.
parent e1724883
...@@ -11,6 +11,11 @@ module Projects ...@@ -11,6 +11,11 @@ module Projects
end end
def execute def execute
# If the pages were never deployed, we can't write out the config, as the
# directory would not exist.
# https://gitlab.com/gitlab-org/gitlab/-/issues/235139
return success unless project.pages_deployed?
unless file_equals?(pages_config_file, pages_config_json) unless file_equals?(pages_config_file, pages_config_json)
update_file(pages_config_file, pages_config_json) update_file(pages_config_file, pages_config_json)
reload_daemon reload_daemon
......
...@@ -142,6 +142,8 @@ module Projects ...@@ -142,6 +142,8 @@ module Projects
end end
def update_pages_config def update_pages_config
return unless project.pages_deployed?
if Feature.enabled?(:async_update_pages_config, project) if Feature.enabled?(:async_update_pages_config, project)
PagesUpdateConfigurationWorker.perform_async(project.id) PagesUpdateConfigurationWorker.perform_async(project.id)
else else
......
...@@ -3,25 +3,33 @@ ...@@ -3,25 +3,33 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Projects::UpdatePagesConfigurationService do RSpec.describe Projects::UpdatePagesConfigurationService do
let(:project) { create(:project) }
let(:service) { described_class.new(project) } let(:service) { described_class.new(project) }
describe "#execute" do describe "#execute" do
let(:file) { Tempfile.new('pages-test') }
subject { service.execute } subject { service.execute }
after do context 'when pages are deployed' do
file.close let_it_be(:project) do
file.unlink create(:project).tap(&:mark_pages_as_deployed)
end end
let(:file) { Tempfile.new('pages-test') }
before do before do
allow(service).to receive(:pages_config_file).and_return(file.path) allow(service).to receive(:pages_config_file).and_return(file.path)
end end
after do
file.close
file.unlink
end
context 'when configuration changes' do context 'when configuration changes' do
it 'updates the .update file' do it 'updates the config and reloads the daemon' do
allow(service).to receive(:update_file).and_call_original
expect(service).to receive(:update_file).with(file.path, an_instance_of(String))
.and_call_original
expect(service).to receive(:reload_daemon).and_call_original expect(service).to receive(:reload_daemon).and_call_original
expect(subject).to include(status: :success) expect(subject).to include(status: :success)
...@@ -50,4 +58,21 @@ RSpec.describe Projects::UpdatePagesConfigurationService do ...@@ -50,4 +58,21 @@ RSpec.describe Projects::UpdatePagesConfigurationService do
end end
end end
end end
context 'when pages are not deployed' do
let_it_be(:project) do
create(:project).tap(&:mark_pages_as_not_deployed)
end
it 'returns successfully' do
expect(subject).to eq(status: :success)
end
it 'does not update the config' do
expect(service).not_to receive(:update_file)
subject
end
end
end
end end
...@@ -397,18 +397,30 @@ RSpec.describe Projects::UpdateService do ...@@ -397,18 +397,30 @@ RSpec.describe Projects::UpdateService do
end end
shared_examples 'updating pages configuration' do shared_examples 'updating pages configuration' do
it 'schedules the `PagesUpdateConfigurationWorker`' do it 'schedules the `PagesUpdateConfigurationWorker` when pages are deployed' do
project.mark_pages_as_deployed
expect(PagesUpdateConfigurationWorker).to receive(:perform_async).with(project.id) expect(PagesUpdateConfigurationWorker).to receive(:perform_async).with(project.id)
subject subject
end end
it "does not schedule a job when pages aren't deployed" do
project.mark_pages_as_not_deployed
expect(PagesUpdateConfigurationWorker).not_to receive(:perform_async).with(project.id)
subject
end
context 'when `async_update_pages_config` is disabled' do context 'when `async_update_pages_config` is disabled' do
before do before do
stub_feature_flags(async_update_pages_config: false) stub_feature_flags(async_update_pages_config: false)
end end
it 'calls Projects::UpdatePagesConfigurationService' do it 'calls Projects::UpdatePagesConfigurationService when pages are deployed' do
project.mark_pages_as_deployed
expect(Projects::UpdatePagesConfigurationService) expect(Projects::UpdatePagesConfigurationService)
.to receive(:new) .to receive(:new)
.with(project) .with(project)
...@@ -416,6 +428,15 @@ RSpec.describe Projects::UpdateService do ...@@ -416,6 +428,15 @@ RSpec.describe Projects::UpdateService do
subject subject
end end
it "does not update pages config when pages aren't deployed" do
project.mark_pages_as_not_deployed
expect(Projects::UpdatePagesConfigurationService)
.not_to receive(:new)
subject
end
end end
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