instance method queue_as

Ruby on Rails 6.1.7.10

Since v4.2.9

Available in: v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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 allowing self.arguments to be accessed 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

Parameters

part_name opt = nil
block block
Source
# File activejob/lib/active_job/queue_name.rb, line 40
      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

Defined in activejob/lib/active_job/queue_name.rb line 40 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveJob::QueueName::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close