Commit 61d3aae6 authored by Toon Claes's avatar Toon Claes

Only write to tracking database when node is a Geo secondary

parent 1ccf720c
......@@ -7,17 +7,16 @@ module EE
private
override :save_result
def save_result(project, failure)
# TODO: Check for Geo
def save_result(project, result)
return super unless ::Gitlab::Geo.secondary?
# TODO: What if project registry does not exist
project_registry = ::Geo::ProjectRegistry.find_or_initialize_by(project: project)
project_registry = Geo::ProjectRegistry.find_by(project_id: project.id)
project_registry.update_columns(
last_repository_check_failed: failure,
project_registry.assign_attributes(
last_repository_check_failed: !result,
last_repository_check_at: Time.now
)
project_registry.save!
end
end
end
......
require 'spec_helper'
describe EE::RepositoryCheck::SingleRepositoryWorker do
include ::EE::GeoHelpers
set(:project) { create(:project) }
set(:project_registry) { create(:geo_project_registry, project: project) }
set(:secondary) { create(:geo_node) }
subject(:worker) { RepositoryCheck::SingleRepositoryWorker.new }
it 'saves results to Geo registry' do
expect do
worker.perform(project.id)
end.to change { project_registry.reload.last_repository_check_at }
context 'Geo primary' do
set(:primary) { create(:geo_node, :primary) }
before do
stub_current_geo_node(primary)
end
it 'saves results to main database' do
expect do
worker.perform(project.id)
end.to change { project.reload.last_repository_check_at }
expect(project.last_repository_check_failed).to be_falsy
end
end
context 'Geo secondary' do
set(:project_registry) { create(:geo_project_registry, project: project) }
set(:secondary) { create(:geo_node) }
before do
stub_current_geo_node(secondary)
end
it 'saves results to Geo registry' do
expect do
worker.perform(project.id)
end.to change { project_registry.reload.last_repository_check_at }
expect(project_registry.last_repository_check_failed).to be_falsy
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