Sha256: eaae9bf254f5b60adb682fd5d648d3b168223de3d4811fd0b1d76f70925b689d

Contents?: true

Size: 1.59 KB

Versions: 20

Compression:

Stored size: 1.59 KB

Contents

require "active_support/core_ext/string/inflections"

module ActiveJob
  # The <tt>ActiveJob::QueueAdapter</tt> module is used to load the
  # correct adapter. The default queue adapter is the +:async+ queue.
  module QueueAdapter #:nodoc:
    extend ActiveSupport::Concern

    included do
      class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false
      self.queue_adapter = :async
    end

    # Includes the setter method for changing the active queue adapter.
    module ClassMethods
      # Returns the backend queue provider. The default queue adapter
      # is the +:async+ queue. See QueueAdapters for more information.
      def queue_adapter
        _queue_adapter
      end

      # Specify the backend queue provider. The default queue adapter
      # is the +:async+ queue. See QueueAdapters for more
      # information.
      def queue_adapter=(name_or_adapter_or_class)
        self._queue_adapter = interpret_adapter(name_or_adapter_or_class)
      end

      private

        def interpret_adapter(name_or_adapter_or_class)
          case name_or_adapter_or_class
          when Symbol, String
            ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new
          else
            if queue_adapter?(name_or_adapter_or_class)
              name_or_adapter_or_class
            else
              raise ArgumentError
            end
          end
        end

        QUEUE_ADAPTER_METHODS = [:enqueue, :enqueue_at].freeze

        def queue_adapter?(object)
          QUEUE_ADAPTER_METHODS.all? { |meth| object.respond_to?(meth) }
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activejob-5.1.7 lib/active_job/queue_adapter.rb
activejob-5.1.7.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.6.2 lib/active_job/queue_adapter.rb
activejob-5.1.6.1 lib/active_job/queue_adapter.rb
activejob-5.1.6 lib/active_job/queue_adapter.rb
activejob-5.1.5 lib/active_job/queue_adapter.rb
activejob-5.1.5.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.4 lib/active_job/queue_adapter.rb
activejob-5.1.4.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.3 lib/active_job/queue_adapter.rb
activejob-5.1.3.rc3 lib/active_job/queue_adapter.rb
activejob-5.1.3.rc2 lib/active_job/queue_adapter.rb
activejob-5.1.3.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.2 lib/active_job/queue_adapter.rb
activejob-5.1.2.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.1 lib/active_job/queue_adapter.rb
activejob-5.1.0 lib/active_job/queue_adapter.rb
activejob-5.1.0.rc2 lib/active_job/queue_adapter.rb
activejob-5.1.0.rc1 lib/active_job/queue_adapter.rb
activejob-5.1.0.beta1 lib/active_job/queue_adapter.rb