Commit 6829b846 authored by Michael Kozono's avatar Michael Kozono

Mark disabled wiki as fully synced

parent 73d1fab8
......@@ -2,6 +2,7 @@ module Geo
class ProjectSyncWorker
include ApplicationWorker
include GeoQueue
include Gitlab::Geo::LogHelpers
sidekiq_options retry: 3, dead: false
......@@ -16,11 +17,11 @@ module Geo
project = registry.project
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
end
unflag_disabled_wiki(registry)
mark_disabled_wiki_as_synced(registry)
Geo::RepositorySyncService.new(project).execute if registry.repository_sync_due?(scheduled_time)
Geo::WikiSyncService.new(project).execute if registry.wiki_sync_due?(scheduled_time)
......@@ -28,10 +29,21 @@ module Geo
private
def unflag_disabled_wiki(registry)
return unless registry.resync_wiki?
def mark_disabled_wiki_as_synced(registry)
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
......@@ -107,19 +107,60 @@ RSpec.describe Geo::ProjectSyncWorker do
before do
project.update!(wiki_enabled: false)
subject.perform(project.id, Time.now)
end
it 'syncs the project repository' do
subject.perform(project.id, Time.now)
expect(repository_sync_service).to have_received(:execute)
end
it 'does not sync the project wiki' do
subject.perform(project.id, Time.now)
expect(wiki_sync_service).not_to have_received(:execute)
end
it 'unflags wiki for sync, to remove it from Geo wiki queries' do
expect(registry.reload.resync_wiki).to be_falsey
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.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
......
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