Module: ActiveJob::QueueName::ClassMethods
Relationships & Source Files | |
Defined in: | activejob/lib/active_job/queue_name.rb |
Overview
Includes the ability to override the default queue name and prefix.
Class Attribute Summary
- .default_queue_name (also: #default_queue_name) rw
Instance Attribute Summary
Instance Method Summary
-
#queue_as(part_name = nil, &block)
Specifies the name of the queue to process the job on.
- #queue_name_from_part(part_name) Internal use only
Class Attribute Details
.default_queue_name (rw) Also known as: #default_queue_name
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 9
mattr_accessor :default_queue_name, default: "default"
Instance Attribute Details
#default_queue_name (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_name.rb', line 9
mattr_accessor :default_queue_name, default: "default"
Instance Method Details
#queue_as(part_name = nil, &block)
Specifies the name of the queue to process the job on.
class PublishToFeedJob < ActiveJob::Base
queue_as :feeds
def perform(post)
post.to_feed!
end
end
Can be given a block that will evaluate in the context of the job so that a dynamic queue name can be applied:
class PublishToFeedJob < ApplicationJob
queue_as do
post = self.arguments.first
if post.paid?
:paid_feeds
else
:feeds
end
end
def perform(post)
post.to_feed!
end
end
# File 'activejob/lib/active_job/queue_name.rb', line 39
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
#queue_name_from_part(part_name)
This method is for internal use only.
[ GitHub ]
# File 'activejob/lib/active_job/queue_name.rb', line 47
def queue_name_from_part(part_name) # :nodoc: queue_name = part_name || default_queue_name name_parts = [queue_name_prefix.presence, queue_name] -name_parts.compact.join(queue_name_delimiter) end