summaryrefslogtreecommitdiff
path: root/lib/gitlab/sidekiq_config/dummy_worker.rb
blob: 8a2ea1acaab63c252b31df415e8b7bc284b424e5 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

module Gitlab
  module SidekiqConfig
    # For queues that don't have explicit workers - default and mailers
    class DummyWorker
      ATTRIBUTE_METHODS = {
        name: :name,
        has_external_dependencies: :worker_has_external_dependencies?,
        urgency: :get_urgency,
        resource_boundary: :get_worker_resource_boundary,
        idempotent: :idempotent?,
        weight: :get_weight,
        tags: :get_tags
      }.freeze

      def initialize(attributes = {})
        @attributes = attributes
      end

      def generated_queue_name
        @attributes[:queue]
      end

      def queue_namespace
        nil
      end

      # All dummy workers are unowned; get the feature category from the
      # context if available.
      def get_feature_category
        Gitlab::ApplicationContext.current_context_attribute('meta.feature_category') || :not_owned
      end

      def feature_category_not_owned?
        true
      end

      def get_worker_context
        nil
      end

      def context_for_arguments(*)
        nil
      end

      ATTRIBUTE_METHODS.each do |attribute, meth|
        define_method meth do
          @attributes[attribute]
        end
      end
    end
  end
end