Module: ActiveJob::QueuePriority::ClassMethods
| Relationships & Source Files | |
| Defined in: | activejob/lib/active_job/queue_priority.rb |
Overview
Includes the ability to override the default queue priority.
Instance Attribute Summary
Instance Method Summary
-
#queue_with_priority(priority = nil, &block)
Specifies the priority of the queue to create the job with.
Instance Attribute Details
#default_priority (rw)
[ GitHub ]# File 'activejob/lib/active_job/queue_priority.rb', line 11
delegate :default_priority, :default_priority=, to: QueuePriority
Instance Method Details
#queue_with_priority(priority = nil, &block)
Specifies the priority of the queue to create the job with.
class PublishToFeedJob < ActiveJob::Base
queue_with_priority 50
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 priority can be applied:
class PublishToFeedJob < ApplicationJob
queue_with_priority do
post = self.arguments.first
if post.paid?
10
else
50
end
end
def perform(post)
post.to_feed!
end
end
# File 'activejob/lib/active_job/queue_priority.rb', line 41
def queue_with_priority(priority = nil, &block) if block_given? self.priority = ActiveSupport::Ractors.try_shareable_proc(block) else self.priority = priority end end