summaryrefslogtreecommitdiff
path: root/lib/gitlab/action_cable/request_store_callbacks.rb
blob: a9f30b0fc10545e10f90c3db635c95fe1604b16b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

module Gitlab
  module ActionCable
    module RequestStoreCallbacks
      def self.install
        ::ActionCable::Server::Worker.set_callback :work, :around, &wrapper
        ::ActionCable::Channel::Base.set_callback :subscribe, :around, &wrapper
        ::ActionCable::Channel::Base.set_callback :unsubscribe, :around, &wrapper
      end

      def self.wrapper
        lambda do |_, inner|
          ::Gitlab::WithRequestStore.with_request_store do
            inner.call
          end
        end
      end
    end
  end
end