Commit 7f90ff77 authored by Toon Claes's avatar Toon Claes

Load project ids from tracking database when searching for batch

Closes gitlab-org/gitlab-ee#5564
parent 64c698c4
module RepositoryCheck module RepositoryCheck
class BatchWorker class BatchWorker
prepend ::EE::RepositoryCheck::BatchWorker
include ApplicationWorker include ApplicationWorker
include CronjobQueue include CronjobQueue
......
module EE
module RepositoryCheck
module BatchWorker
extend ActiveSupport::Concern
extend ::Gitlab::Utils::Override
private
override :never_checked_project_ids
def never_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary?
Geo::ProjectRegistry.synced_repos.synced_wikis
.where(last_repository_check_at: nil)
.where('last_repository_synced_at < ?', 24.hours.ago)
.where('last_wiki_synced_at < ?', 24.hours.ago)
.limit(batch_size).pluck(:project_id)
end
override :old_checked_project_ids
def old_checked_project_ids(batch_size)
return super unless ::Gitlab::Geo.secondary?
Geo::ProjectRegistry.synced_repos.synced_wikis
.where('last_repository_check_at < ?', 1.month.ago)
.reorder(last_repository_check_at: :asc)
.limit(batch_size).pluck(:project_id)
end
end
end
end
---
title: Run repository verification on Geo secondary
merge_request: 5550
author:
type: added
require 'spec_helper'
describe EE::RepositoryCheck::BatchWorker do
include ::EE::GeoHelpers
subject(:worker) { RepositoryCheck::BatchWorker.new }
context 'Geo primary' do
set(:primary) { create(:geo_node, :primary) }
before do
stub_current_geo_node(primary)
end
it 'loads project ids from main database' do
projects = create_list(:project, 3, created_at: 1.week.ago)
expect(worker.perform).to eq(projects.map(&:id))
end
end
context 'Geo secondary' do
set(:secondary) { create(:geo_node) }
before do
stub_current_geo_node(secondary)
end
it 'loads project ids from tracking database' do
project_registries = create_list(:geo_project_registry, 3, :synced)
expect(worker.perform).to eq(project_registries.map(&:project_id))
end
it 'loads project ids that were checked more than a month ago from tracking database' do
project_registries = create_list(:geo_project_registry, 3, :synced,
last_repository_check_failed: false,
last_repository_check_at: 42.days.ago)
expect(worker.perform).to eq(project_registries.map(&:project_id))
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