包含覆盖默认队列优先级的能力。
方法
实例公共方法
queue_with_priority(priority = nil, &block) 链接
指定创建作业时使用的队列的优先级。
class PublishToFeedJob < ActiveJob::Base queue_with_priority 50 def perform(post) post.to_feed! end end
可以提供一个块,该块将在作业的上下文中进行评估,以便应用动态优先级
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
来源: 显示 | 在 GitHub 上
# File activejob/lib/active_job/queue_priority.rb, line 39 def queue_with_priority(priority = nil, &block) if block_given? self.priority = block else self.priority = priority end end