Class: Gitlab::SidekiqSharding::Router
- Inherits:
-
Object
- Object
- Gitlab::SidekiqSharding::Router
- Defined in:
- lib/gitlab/sidekiq_sharding/router.rb
Class Method Summary collapse
- .enabled? ⇒ Boolean
- .get_shard_instance(store_name) ⇒ Object
- .migrated_shards ⇒ Object
- .route(klass) ⇒ Object
- .with_routed_client ⇒ Object
Class Method Details
.enabled? ⇒ Boolean
7 8 9 |
# File 'lib/gitlab/sidekiq_sharding/router.rb', line 7 def enabled? Gitlab::Redis::Queues.instances.size > 1 && Feature.enabled?(:enable_sidekiq_shard_router, type: :ops) end |
.get_shard_instance(store_name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gitlab/sidekiq_sharding/router.rb', line 11 def get_shard_instance(store_name) store_name = route_to(store_name) instance = Gitlab::Redis::Queues.instances[store_name] # To guard against setups with a configured config/gitlab.yml but stale config/redis.yml if instance.nil? store_name = Gitlab::Redis::Queues::SIDEKIQ_MAIN_SHARD_INSTANCE_NAME instance = Gitlab::Redis::Queues.instances[Gitlab::Redis::Queues::SIDEKIQ_MAIN_SHARD_INSTANCE_NAME] end [ store_name, instance.sidekiq_redis ] end |
.migrated_shards ⇒ Object
50 51 52 |
# File 'lib/gitlab/sidekiq_sharding/router.rb', line 50 def migrated_shards @migrated_shards ||= Set.new(Gitlab::Json.parse(ENV.fetch('SIDEKIQ_MIGRATED_SHARDS', '[]'))) end |
.route(klass) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gitlab/sidekiq_sharding/router.rb', line 27 def route(klass) unless enabled? && klass.respond_to?(:get_sidekiq_options) return Gitlab::SidekiqSharding::Validator.allow_unrouted_sidekiq_calls { yield } end store_name = klass.['store'] redis_name, shard_redis_pool = get_shard_instance(store_name) Gitlab::ApplicationContext.with_context(sidekiq_destination_shard_redis: redis_name) do Sidekiq::Client.via(shard_redis_pool) do yield end end end |