aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/queue_name.rb
blob: 9698835b6e13acb7456209589c686feb989d5ba9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module ActiveJob
  module QueueName
    extend ActiveSupport::Concern

    module ClassMethods
      mattr_accessor(:queue_name_prefix)
      mattr_accessor(:default_queue_name) { "default" }

      def queue_as(part_name)
        queue_name = part_name.to_s.presence || default_queue_name
        name_parts = [queue_name_prefix.presence, queue_name]
        self.queue_name = name_parts.compact.join('_')
      end
    end

    included do
      class_attribute :queue_name
      self.queue_name = default_queue_name
    end
  end
end