Commit 368e60da authored by Stan Hu's avatar Stan Hu

Merge branch 'mk/geo/fix-disabled-wiki-registry' into 'master'

Geo: Mark disabled wiki as fully synced

Closes #5427

See merge request gitlab-org/gitlab-ee!5104
parents 89d99723 8626d6a7
...@@ -2,6 +2,7 @@ module Geo ...@@ -2,6 +2,7 @@ module Geo
class ProjectSyncWorker class ProjectSyncWorker
include ApplicationWorker include ApplicationWorker
include GeoQueue include GeoQueue
include Gitlab::Geo::LogHelpers
sidekiq_options retry: 3, dead: false sidekiq_options retry: 3, dead: false
...@@ -16,11 +17,11 @@ module Geo ...@@ -16,11 +17,11 @@ module Geo
project = registry.project project = registry.project
if project.nil? if project.nil?
Gitlab::Geo::Logger.error(class: self.class.name, message: "Couldn't find project, skipping syncing", project_id: project_id) log_error("Couldn't find project, skipping syncing", project_id: project_id)
return return
end end
unflag_disabled_wiki(registry) mark_disabled_wiki_as_synced(registry)
Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time) Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time)
Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time) Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time)
...@@ -28,10 +29,21 @@ module Geo ...@@ -28,10 +29,21 @@ module Geo
private private
def unflag_disabled_wiki(registry) def mark_disabled_wiki_as_synced(registry)
return unless registry.resync_wiki? return if registry.project.wiki_enabled?
registry.update!(resync_wiki: false) unless registry.project.wiki_enabled? registry.last_wiki_sync_failure = nil
registry.last_wiki_synced_at = DateTime.now
registry.last_wiki_successful_sync_at = DateTime.now
registry.resync_wiki = false
registry.wiki_retry_count = nil
registry.wiki_retry_at = nil
registry.force_to_redownload_wiki = false
if registry.changed?
success = registry.save
log_info("#{success ? 'Successfully marked' : 'Failed to mark'} disabled wiki as synced", registry_id: registry.id, project_id: registry.project_id)
end
end end
end end
end end
---
title: Mark disabled wikis as fully synced
merge_request: 5104
author:
type: fixed
...@@ -107,19 +107,60 @@ RSpec.describe Geo::ProjectSyncWorker do ...@@ -107,19 +107,60 @@ RSpec.describe Geo::ProjectSyncWorker do
before do before do
project.update!(wiki_enabled: false) project.update!(wiki_enabled: false)
subject.perform(project.id, Time.now)
end end
it 'syncs the project repository' do it 'syncs the project repository' do
subject.perform(project.id, Time.now)
expect(repository_sync_service).to have_received(:execute) expect(repository_sync_service).to have_received(:execute)
end end
it 'does not sync the project wiki' do it 'does not sync the project wiki' do
subject.perform(project.id, Time.now)
expect(wiki_sync_service).not_to have_received(:execute) expect(wiki_sync_service).not_to have_received(:execute)
end end
it 'unflags wiki for sync, to remove it from Geo wiki queries' do context 'when the wiki has failed to sync before' do
let!(:registry) { create(:geo_project_registry, :wiki_sync_failed, project: project) }
it 'marks the wiki as synced, to remove it from failed Geo wiki queries' do
subject.perform(project.id, Time.now)
expect(registry.reload.resync_wiki).to be_falsey expect(registry.reload.resync_wiki).to be_falsey
expect(registry.reload.last_wiki_sync_failure).to be_nil
expect(registry.reload.last_wiki_synced_at).to be_present
expect(registry.reload.last_wiki_successful_sync_at).to be_present
expect(registry.reload.wiki_retry_count).to be_nil
expect(registry.reload.wiki_retry_at).to be_nil
expect(registry.reload.force_to_redownload_wiki).to be_falsey
end
it 'logs that the wiki was marked as not needing a sync' do
expect(subject).to receive(:log_info).with("Successfully marked disabled wiki as synced", registry_id: registry.id, project_id: registry.project_id)
subject.perform(project.id, Time.now)
end
end
context 'when the wiki has never been synced before' do
it 'marks the wiki as synced, to remove it from out-of-sync Geo wiki queries' do
subject.perform(project.id, Time.now)
expect(registry.reload.resync_wiki).to be_falsey
expect(registry.reload.last_wiki_sync_failure).to be_nil
expect(registry.reload.last_wiki_synced_at).to be_present
expect(registry.reload.last_wiki_successful_sync_at).to be_present
expect(registry.reload.wiki_retry_count).to be_nil
expect(registry.reload.wiki_retry_at).to be_nil
expect(registry.reload.force_to_redownload_wiki).to be_falsey
end
it 'logs that the wiki was marked as not needing a sync' do
expect(subject).to receive(:log_info).with("Successfully marked disabled wiki as synced", registry_id: registry.id, project_id: registry.project_id)
subject.perform(project.id, Time.now)
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