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 ...@@ -7,17 +7,16 @@ module EE
private private
override :save_result override :save_result
def save_result(project, failure) def save_result(project, result)
# TODO: Check for Geo 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.assign_attributes(
last_repository_check_failed: !result,
project_registry.update_columns(
last_repository_check_failed: failure,
last_repository_check_at: Time.now last_repository_check_at: Time.now
) )
project_registry.save!
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe EE::RepositoryCheck::SingleRepositoryWorker do describe EE::RepositoryCheck::SingleRepositoryWorker do
include ::EE::GeoHelpers
set(:project) { create(:project) } set(:project) { create(:project) }
subject(:worker) { RepositoryCheck::SingleRepositoryWorker.new }
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(:project_registry) { create(:geo_project_registry, project: project) }
set(:secondary) { create(:geo_node) } set(:secondary) { create(:geo_node) }
subject(:worker) { RepositoryCheck::SingleRepositoryWorker.new } before do
stub_current_geo_node(secondary)
end
it 'saves results to Geo registry' do it 'saves results to Geo registry' do
expect do expect do
worker.perform(project.id) worker.perform(project.id)
end.to change { project_registry.reload.last_repository_check_at } end.to change { project_registry.reload.last_repository_check_at }
expect(project_registry.last_repository_check_failed).to be_falsy
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