Class: Gitlab::SidekiqMiddleware::WorkerContext::Client

Inherits:
Object
  • Object
show all
Includes:
Gitlab::SidekiqMiddleware::WorkerContext
Defined in:
lib/gitlab/sidekiq_middleware/worker_context/client.rb

Instance Method Summary collapse

Instance Method Details

#call(worker_class_or_name, job, _queue, _redis_pool, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/sidekiq_middleware/worker_context/client.rb', line 9

def call(worker_class_or_name, job, _queue, _redis_pool, &block)
  worker_class = find_worker(worker_class_or_name.to_s.safe_constantize, job)

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

  context_for_args = worker_class.context_for_arguments(job['args'])

  wrap_in_optional_context(context_for_args) do
    # This should be inside the context for the arguments so
    # that we don't override the feature category on the worker
    # with the one from the caller.

    root_caller_id = Gitlab::ApplicationContext.current_context_attribute(:root_caller_id) ||
      Gitlab::ApplicationContext.current_context_attribute(:caller_id)

    context = {
      root_caller_id: root_caller_id
    }

    # We do not want to set anything explicitly in the context
    # when the feature category is 'not_owned'.
    unless worker_class.feature_category_not_owned?
      context[:feature_category] = worker_class.get_feature_category.to_s
    end

    Gitlab::ApplicationContext.with_context(**context, &block)
  end
end