2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
|
|
|
module WorkerContext
|
|
|
|
class Client
|
|
|
|
include Gitlab::SidekiqMiddleware::WorkerContext
|
|
|
|
|
|
|
|
def call(worker_class_or_name, job, _queue, _redis_pool, &block)
|
2021-11-18 22:05:49 +05:30
|
|
|
worker_class = find_worker(worker_class_or_name.to_s.safe_constantize, job)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
# This is not a worker we know about, perhaps from a gem
|
2020-03-13 15:44:24 +05:30
|
|
|
return yield unless worker_class
|
2021-11-18 22:05:49 +05:30
|
|
|
return yield unless worker_class.respond_to?(:context_for_arguments)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
context_for_args = worker_class.context_for_arguments(job['args'])
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
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.
|
2021-11-18 22:05:49 +05:30
|
|
|
#
|
|
|
|
# We do not want to set anything explicitly in the context
|
|
|
|
# when the feature category is 'not_owned'.
|
|
|
|
if worker_class.feature_category_not_owned?
|
|
|
|
yield
|
|
|
|
else
|
|
|
|
Gitlab::ApplicationContext.with_context(feature_category: worker_class.get_feature_category.to_s, &block)
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|