1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/queue_priority.rb
David Heinemeier Hansson 1c275d812f Add option for class_attribute default (#29270)
* Allow a default value to be declared for class_attribute

* Convert to using class_attribute default rather than explicit setter

* Removed instance_accessor option by mistake

* False is a valid default value

* Documentation
2017-05-29 18:01:50 +02:00

41 lines
1,018 B
Ruby

module ActiveJob
module QueuePriority
extend ActiveSupport::Concern
# Includes the ability to override the default queue priority.
module ClassMethods
mattr_accessor(:default_priority)
# 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
#
# Specify either an argument or a block.
def queue_with_priority(priority = nil, &block)
if block_given?
self.priority = block
else
self.priority = priority
end
end
end
included do
class_attribute :priority, instance_accessor: false, default: default_priority
end
# Returns the priority that the job will be created with
def priority
if @priority.is_a?(Proc)
@priority = instance_exec(&@priority)
end
@priority
end
end
end