Skip to content
代码片段 群组 项目
未验证 提交 2b8b25da 编辑于 作者: Sylvester Chin's avatar Sylvester Chin 提交者: GitLab
浏览文件

Merge branch 'sc1-lock-migrated-shard' into 'master'

Define SIDEKIQ_MIGRATED_SHARDS for sidekiq shard router

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/150591



Merged-by: default avatarSylvester Chin <schin@gitlab.com>
Approved-by: default avatarBob Van Landuyt <bob@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -15,6 +15,9 @@ def load_cron_jobs!
end
end
# initialise migrated_shards on start-up to catch any malformed SIDEKIQ_MIGRATED_SHARD lists.
Gitlab::SidekiqSharding::Router.migrated_shards
# Custom Queues configuration
#
# We omit :command_builder since Sidekiq::RedisConnection performs a deep clone using
......
......@@ -38,11 +38,16 @@ def route(klass)
end
end
def migrated_shards
@migrated_shards ||= Set.new(Gitlab::Json.parse(ENV.fetch('SIDEKIQ_MIGRATED_SHARDS', '[]')))
end
private
def route_to(shard_name)
# early return if main since we do not want a redundant feature flag check
return shard_name if shard_name == Gitlab::Redis::Queues::SIDEKIQ_MAIN_SHARD_INSTANCE_NAME
return shard_name if migrated_shards.include?(shard_name)
if shard_name.nil? ||
Feature.disabled?(:"sidekiq_route_to_#{shard_name}", type: :worker, default_enabled_if_undefined: false)
......
......@@ -106,6 +106,25 @@
end
end
context 'when shard is migrated' do
before do
stub_env('SIDEKIQ_MIGRATED_SHARDS', "[\"queues_shard_test\"]")
if described_class.instance_variable_defined?(:@migrated_shards)
described_class.remove_instance_variable(:@migrated_shards)
end
end
it 'returns shard without checking feature flag' do
expect(Feature).not_to receive(:enabled?)
name, redis = get_test_shard
expect(name).to eq('queues_shard_test')
expect(redis).to eq(shard_sidekiq_redis)
end
end
context 'when feature flag is enabled' do
before do
allow(Feature).to receive(:enabled?)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册