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

module Gitlab
  module SidekiqMiddleware
    module WorkerContext
      class Server
        include Gitlab::SidekiqMiddleware::WorkerContext

        def call(worker, job, _queue, &block)
          worker_class = find_worker(worker.class, job)

          # This is not a worker we know about, perhaps from a gem
          return yield unless worker_class.respond_to?(:get_worker_context)

          Gitlab::ApplicationContext.with_context(feature_category: worker_class.get_feature_category.to_s) do
            # Use the context defined on the class level as the more specific context
            wrap_in_optional_context(worker_class.get_worker_context, &block)
          end
        end
      end
    end
  end
end