1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_name.rb

39 lines
994 B
Ruby
Raw Normal View History

2014-05-19 05:04:23 -04:00
module ActiveJob
module QueueName
extend ActiveSupport::Concern
2014-05-19 05:04:23 -04:00
module ClassMethods
mattr_accessor(:queue_name_prefix)
mattr_accessor(:default_queue_name) { "default" }
2014-08-25 10:34:50 -04:00
def queue_as(part_name=nil, &block)
if block_given?
self.queue_name = block
else
self.queue_name = queue_name_from_part(part_name)
end
end
def queue_name_from_part(part_name) #:nodoc:
queue_name = part_name.to_s.presence || default_queue_name
name_parts = [queue_name_prefix.presence, queue_name]
2014-08-25 10:34:50 -04:00
name_parts.compact.join('_')
end
end
included do
2014-08-25 10:34:50 -04:00
class_attribute :queue_name, instance_accessor: false
self.queue_name = default_queue_name
2014-05-19 05:04:23 -04:00
end
2014-08-25 10:34:50 -04:00
# Returns the name of the queue the job will be run on
def queue_name
if @queue_name.is_a?(Proc)
@queue_name = self.class.queue_name_from_part(instance_exec(&@queue_name))
end
@queue_name
end
2014-05-19 05:04:23 -04:00
end
end