2020-01-31 09:08:53 +00:00
|
|
|
# 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-09-21 00:09:28 +00:00
|
|
|
worker_class = find_worker(worker_class_or_name.to_s.safe_constantize, job)
|
2020-01-31 09:08:53 +00:00
|
|
|
|
2021-09-21 00:09:28 +00:00
|
|
|
# This is not a worker we know about, perhaps from a gem
|
2020-01-31 09:08:53 +00:00
|
|
|
return yield unless worker_class
|
2021-09-21 00:09:28 +00:00
|
|
|
return yield unless worker_class.respond_to?(:context_for_arguments)
|
2020-01-31 09:08:53 +00:00
|
|
|
|
|
|
|
context_for_args = worker_class.context_for_arguments(job['args'])
|
|
|
|
|
2021-09-21 00:09:28 +00:00
|
|
|
wrap_in_optional_context(context_for_args, &block)
|
2020-01-31 09:08:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|