Commit 6a71676d authored by Mike Kozono's avatar Mike Kozono

Trigger background verification every minute

The trigger `#trigger_background_verification` will be implemented in
the following commit.
parent 86341c02
...@@ -553,6 +553,9 @@ Gitlab.ee do ...@@ -553,6 +553,9 @@ Gitlab.ee do
Settings.cron_jobs['adjourned_projects_deletion_cron_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['adjourned_projects_deletion_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['adjourned_projects_deletion_cron_worker']['cron'] ||= '0 4 * * *' Settings.cron_jobs['adjourned_projects_deletion_cron_worker']['cron'] ||= '0 4 * * *'
Settings.cron_jobs['adjourned_projects_deletion_cron_worker']['job_class'] = 'AdjournedProjectsDeletionCronWorker' Settings.cron_jobs['adjourned_projects_deletion_cron_worker']['job_class'] = 'AdjournedProjectsDeletionCronWorker'
Settings.cron_jobs['geo_verification_cron_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_verification_cron_worker']['cron'] ||= '* * * * *'
Settings.cron_jobs['geo_verification_cron_worker']['job_class'] ||= 'Geo::VerificationCronWorker'
Settings.cron_jobs['geo_file_download_dispatch_worker'] ||= Settingslogic.new({}) Settings.cron_jobs['geo_file_download_dispatch_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['geo_file_download_dispatch_worker']['cron'] ||= '*/1 * * * *' Settings.cron_jobs['geo_file_download_dispatch_worker']['cron'] ||= '*/1 * * * *'
Settings.cron_jobs['geo_file_download_dispatch_worker']['job_class'] ||= 'Geo::FileDownloadDispatchWorker' Settings.cron_jobs['geo_file_download_dispatch_worker']['job_class'] ||= 'Geo::FileDownloadDispatchWorker'
......
...@@ -7,7 +7,10 @@ module Geo ...@@ -7,7 +7,10 @@ module Geo
include Delay include Delay
class_methods do class_methods do
extend Gitlab::Utils::Override
# If replication is disabled, then so is verification. # If replication is disabled, then so is verification.
override :verification_enabled?
def verification_enabled? def verification_enabled?
enabled? && verification_feature_flag_enabled? enabled? && verification_feature_flag_enabled?
end end
...@@ -25,6 +28,13 @@ module Geo ...@@ -25,6 +28,13 @@ module Geo
Feature.enabled?(:geo_framework_verification) Feature.enabled?(:geo_framework_verification)
end end
# Called every minute by VerificationCronWorker
def trigger_background_verification
return false unless verification_enabled?
# TODO: ::Geo::VerificationBatchWorker.perform_with_capacity(self)
end
def checksummed_count def checksummed_count
# When verification is disabled, this returns nil. # When verification is disabled, this returns nil.
# Bonus: This causes the progress bar to be hidden. # Bonus: This causes the progress bar to be hidden.
......
...@@ -187,6 +187,14 @@ ...@@ -187,6 +187,14 @@
:weight: 1 :weight: 1
:idempotent: :idempotent:
:tags: [] :tags: []
- :name: cronjob:geo_verification_cron
:feature_category: :geo_replication
:has_external_dependencies:
:urgency: :low
:resource_boundary: :unknown
:weight: 1
:idempotent: true
:tags: []
- :name: cronjob:historical_data - :name: cronjob:historical_data
:feature_category: :provision :feature_category: :provision
:has_external_dependencies: :has_external_dependencies:
......
# frozen_string_literal: true
module Geo
# Calls trigger_background_verification on every enabled Replicator class,
# every minute.
#
class VerificationCronWorker
include ApplicationWorker
include ::Gitlab::Geo::LogHelpers
# This worker does not perform work scoped to a context
include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
idempotent!
feature_category :geo_replication
def perform
Gitlab::Geo.verification_enabled_replicator_classes.each do |replicator_class|
replicator_class.trigger_background_verification
end
end
end
end
...@@ -171,5 +171,9 @@ module Gitlab ...@@ -171,5 +171,9 @@ module Gitlab
def self.enabled_replicator_classes def self.enabled_replicator_classes
REPLICATOR_CLASSES.select(&:enabled?) REPLICATOR_CLASSES.select(&:enabled?)
end end
def self.verification_enabled_replicator_classes
REPLICATOR_CLASSES.select(&:verification_enabled?)
end
end end
end end
...@@ -181,6 +181,11 @@ module Gitlab ...@@ -181,6 +181,11 @@ module Gitlab
:"geo_#{replicable_name}_replication" :"geo_#{replicable_name}_replication"
end end
# Overridden by VerifiableReplicator, if it is included
def self.verification_enabled?
false
end
# @param [ActiveRecord::Base] model_record # @param [ActiveRecord::Base] model_record
# @param [Integer] model_record_id # @param [Integer] model_record_id
def initialize(model_record: nil, model_record_id: nil) def initialize(model_record: nil, model_record_id: nil)
......
...@@ -366,4 +366,33 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do ...@@ -366,4 +366,33 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do
end end
end end
end end
describe '.verification_enabled_replicator_classes' do
it 'returns an Array of replicator classes' do
result = described_class.verification_enabled_replicator_classes
expect(result).to be_an(Array)
expect(result).to include(Geo::PackageFileReplicator)
end
context 'when replication is disabled' do
before do
stub_feature_flags(geo_package_file_replication: false)
end
it 'does not return the replicator class' do
expect(described_class.verification_enabled_replicator_classes).not_to include(Geo::PackageFileReplicator)
end
end
context 'when verification is disabled' do
before do
stub_feature_flags(geo_package_file_verification: false)
end
it 'does not return the replicator class' do
expect(described_class.verification_enabled_replicator_classes).not_to include(Geo::PackageFileReplicator)
end
end
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::VerificationCronWorker, :geo do
describe '#perform' do
it 'calls trigger_background_verification on enabled Replicators' do
replicator = double('replicator')
expect(replicator).to receive(:trigger_background_verification)
expect(Gitlab::Geo).to receive(:verification_enabled_replicator_classes).and_return([replicator])
described_class.new.perform
end
end
it 'uses a cronjob queue' do
expect(subject.sidekiq_options_hash).to include(
'queue' => 'cronjob:geo_verification_cron',
'queue_namespace' => :cronjob
)
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