跳至内容 跳至搜索

包含覆盖默认队列优先级的能力。

方法
Q

实例公共方法

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
# 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