summaryrefslogtreecommitdiff
path: root/app/workers/concerns/worker_context.rb
blob: d85565e3446d44451eb14f501e90e0a2cfc8e400 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module WorkerContext
  extend ActiveSupport::Concern

  class_methods do
    def worker_context(attributes)
      @worker_context = Gitlab::ApplicationContext.new(attributes)
    end

    def get_worker_context
      @worker_context || superclass_context
    end

    private

    def superclass_context
      return unless superclass.include?(WorkerContext)

      superclass.get_worker_context
    end
  end

  def with_context(context, &block)
    Gitlab::ApplicationContext.new(context).use(&block)
  end
end