包含覆寫預設佇列優先權的能力。
方法
執行個體公開方法
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