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_adapter.rb

36 lines
1.1 KiB
Ruby
Raw Normal View History

require 'active_job/queue_adapters/inline_adapter'
require 'active_support/core_ext/string/inflections'
module ActiveJob
# The <tt>ActionJob::QueueAdapter</tt> module is used to load the
# correct adapter. The default queue adapter is the :inline queue.
module QueueAdapter #:nodoc:
2014-08-26 16:08:49 -04:00
extend ActiveSupport::Concern
# Includes the setter method for changing the active queue adapter.
2014-08-26 16:08:49 -04:00
module ClassMethods
mattr_reader(:queue_adapter) { ActiveJob::QueueAdapters::InlineAdapter }
# Specify the backend queue provider. The default queue adapter
# is the :inline queue. See QueueAdapters for more
# information.
2014-08-26 16:08:49 -04:00
def queue_adapter=(name_or_adapter)
@@queue_adapter = \
case name_or_adapter
2014-08-29 16:11:17 -04:00
when :test
ActiveJob::QueueAdapters::TestAdapter.new
2014-08-26 16:08:49 -04:00
when Symbol, String
load_adapter(name_or_adapter)
else
name_or_adapter if name_or_adapter.respond_to?(:enqueue)
2014-08-26 16:08:49 -04:00
end
end
2014-08-26 16:08:49 -04:00
private
def load_adapter(name)
"ActiveJob::QueueAdapters::#{name.to_s.camelize}Adapter".constantize
end
end
end
end