Sha256: 8d02ad999b62861aab6bf93946a5133352421628f02c97f4343be316e15b6309

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

module Delayed
  module Backend
    class JobPreparer
      attr_reader :options, :args

      def initialize(*args)
        @options = args.extract_options!.dup
        @args = args
      end

      def prepare
        set_payload
        set_queue_name
        set_priority
        handle_deprecation
        options
      end

      private

      def set_payload
        options[:payload_object] ||= args.shift
      end

      def set_queue_name
        options[:queue] ||= options[:payload_object].queue_name if options[:payload_object].respond_to?(:queue_name)
        options[:queue] ||= Delayed::Worker.default_queue_name
      end

      def set_priority
        options[:priority] ||= options[:payload_object].priority if options[:payload_object].respond_to?(:priority)
        options[:priority] ||= Delayed::Worker.default_priority
      end

      def handle_deprecation
        unless options[:payload_object].respond_to?(:perform)
          raise ArgumentError,
                'Cannot enqueue items which do not respond to perform'
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
delayed-0.5.5 lib/delayed/backend/job_preparer.rb
delayed-0.5.4 lib/delayed/backend/job_preparer.rb
delayed-0.5.3 lib/delayed/backend/job_preparer.rb
delayed-0.5.2 lib/delayed/backend/job_preparer.rb
delayed-0.5.1 lib/delayed/backend/job_preparer.rb
delayed-0.5.0 lib/delayed/backend/job_preparer.rb
delayed-0.4.0 lib/delayed/backend/job_preparer.rb
delayed-0.3.0 lib/delayed/backend/job_preparer.rb
delayed-0.2.0 lib/delayed/backend/job_preparer.rb
delayed-0.1.1 lib/delayed/backend/job_preparer.rb
delayed-0.1.0 lib/delayed/backend/job_preparer.rb