Commit adf64460 authored by Stan Hu's avatar Stan Hu

Merge branch '4826-geo-wikisyncservice-attempts-to-sync-projects-that-have-no-wiki-1' into 'master'

Resolve "Geo WikiSyncService attempts to sync projects that have no Wiki"

Closes #4826

See merge request gitlab-org/gitlab-ee!4677
parents c84b8eb1 67f4107b
......@@ -21,15 +21,18 @@ module Geo
fetch_geo_mirror(project.wiki.repository)
end
update_registry!(finished_at: DateTime.now, attrs: { last_wiki_sync_failure: nil })
log_info('Finished wiki sync',
update_delay_s: update_delay_in_seconds,
download_time_s: download_time_in_seconds)
mark_sync_as_successful
rescue Gitlab::Git::RepositoryMirroring::RemoteError,
Gitlab::Shell::Error,
ProjectWiki::CouldNotCreateWikiError => e
fail_registry!('Error syncing wiki repository', e)
# In some cases repository does not exists, the only way to know about this is to parse the error text.
# If it does not exist we should consider it as successfuly downloaded.
if e.message.include? Gitlab::GitAccess::ERROR_MESSAGES[:no_repo]
log_info('Repository is not found, marking it as successfully synced')
mark_sync_as_successful
else
fail_registry!('Error syncing wiki repository', e)
end
rescue Gitlab::Git::Repository::NoRepository => e
log_info('Setting force_to_redownload flag')
fail_registry!('Invalid wiki', e, force_to_redownload_wiki: true)
......@@ -45,6 +48,14 @@ module Geo
project.wiki.repository
end
def mark_sync_as_successful
update_registry!(finished_at: DateTime.now, attrs: { last_wiki_sync_failure: nil })
log_info('Finished wiki sync',
update_delay_s: update_delay_in_seconds,
download_time_s: download_time_in_seconds)
end
def retry_count
registry.public_send("#{type}_retry_count") || -1 # rubocop:disable GitlabSecurity/PublicSend
end
......
---
title: 'Fix: Geo WikiSyncService attempts to sync projects that have no Wiki'
merge_request:
author:
type: fixed
......@@ -94,6 +94,19 @@ RSpec.describe Geo::WikiSyncService do
expect(Geo::ProjectRegistry.last.wiki_retry_count).to eq(1)
end
it 'marks sync as successful if no repository found' do
registry = create(:geo_project_registry, project: project)
allow(repository).to receive(:fetch_as_mirror)
.with(url_to_repo, remote_name: 'geo', forced: true)
.and_raise(Gitlab::Shell::Error.new(Gitlab::GitAccess::ERROR_MESSAGES[:no_repo]))
subject.execute
expect(registry.reload.resync_wiki).to be false
expect(registry.last_wiki_successful_sync_at).not_to be nil
end
context 'tracking database' do
it 'creates a new registry if does not exists' do
expect { subject.execute }.to change(Geo::ProjectRegistry, :count).by(1)
......
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