Commit 23e0a289 authored by Mike Kozono's avatar Mike Kozono

Fix replicator class list

In development and test environments, the models which include
`ReplicableModel` may not be loaded yet when
`ReplicableModel.replicators` is called, therefore causing `Replicator`
classes to be missing from the list.

Hard code the list for now, while we take time to implement it properly.
parent 1834d622
...@@ -78,7 +78,7 @@ module Geo ...@@ -78,7 +78,7 @@ module Geo
end end
def replicator_classes def replicator_classes
Gitlab::Geo::ReplicableModel.replicators Gitlab::Geo.replicator_classes
end end
end end
end end
...@@ -157,5 +157,12 @@ module Gitlab ...@@ -157,5 +157,12 @@ module Gitlab
_(template) % { url: url } _(template) % { url: url }
end end
# TODO: Avoid having to maintain a list. Discussions related to possible
# solutions can be found at
# https://gitlab.com/gitlab-org/gitlab/-/issues/227693
def self.replicator_classes
[::Geo::PackageFileReplicator]
end
end end
end end
...@@ -25,8 +25,6 @@ module Gitlab ...@@ -25,8 +25,6 @@ module Gitlab
def with_replicator(klass) def with_replicator(klass)
raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator
Gitlab::Geo::ReplicableModel.add_replicator(klass)
class_eval <<-RUBY, __FILE__, __LINE__ + 1 class_eval <<-RUBY, __FILE__, __LINE__ + 1
define_method :replicator do define_method :replicator do
@_replicator ||= klass.new(model_record: self) @_replicator ||= klass.new(model_record: self)
...@@ -39,16 +37,6 @@ module Gitlab ...@@ -39,16 +37,6 @@ module Gitlab
end end
end end
def self.add_replicator(klass)
@_replicators ||= []
@_replicators << klass
end
def self.replicators
@_replicators ||= []
@_replicators.filter { |replicator| const_defined?(replicator.to_s) }
end
# Geo Replicator # Geo Replicator
# #
# @abstract # @abstract
......
...@@ -335,4 +335,13 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do ...@@ -335,4 +335,13 @@ RSpec.describe Gitlab::Geo, :geo, :request_store do
expect(described_class.interacting_with_primary_message(url)).to eq(message) expect(described_class.interacting_with_primary_message(url)).to eq(message)
end end
end end
describe '.replicator_classes' do
it 'returns an Array of replicator classes' do
result = described_class.replicator_classes
expect(result).to be_an(Array)
expect(result).to include(Geo::PackageFileReplicator)
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