summaryrefslogtreecommitdiff
path: root/lib/gitlab/redis/duplicate_jobs.rb
blob: c76d298da18ab5755baf027151d8d58a524feb1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

module Gitlab
  module Redis
    # Pseudo-store to transition `Gitlab::SidekiqMiddleware::DuplicateJobs` from
    # using `Sidekiq.redis` to using the `SharedState` redis store.
    class DuplicateJobs < ::Gitlab::Redis::Wrapper
      class << self
        def store_name
          'SharedState'
        end

        private

        def redis
          primary_store = ::Redis.new(Gitlab::Redis::SharedState.params)

          # `Sidekiq.redis` is a namespaced redis connection. This means keys are actually being stored under
          # "resque:gitlab:resque:gitlab:duplicate:". For backwards compatibility, we make the secondary store
          # namespaced in the same way, but omit it from the primary so keys have proper format there.
          # rubocop:disable Cop/RedisQueueUsage
          secondary_store = ::Redis::Namespace.new(
            Gitlab::Redis::Queues::SIDEKIQ_NAMESPACE, redis: ::Redis.new(Gitlab::Redis::Queues.params)
          )
          # rubocop:enable Cop/RedisQueueUsage

          MultiStore.new(primary_store, secondary_store, name.demodulize)
        end
      end
    end
  end
end