Sha256: 801d1ca1fe2b73bc21b5fef2a103ce2b614e5dacd5d4f9bd532b192eba380bee

Contents?: true

Size: 1.38 KB

Versions: 26

Compression:

Stored size: 1.38 KB

Contents

module Shoryuken
  class DefaultWorkerRegistry < WorkerRegistry
    def initialize
      @workers = {}
    end

    def batch_receive_messages?(queue)
      !!(@workers[queue] && @workers[queue].get_shoryuken_options['batch'])
    end

    def clear
      @workers.clear
    end

    def fetch_worker(queue, message)
      worker_class = !message.is_a?(Array) &&
                     message.message_attributes &&
                     message.message_attributes['shoryuken_class'] &&
                     message.message_attributes['shoryuken_class'][:string_value]

      worker_class = begin
                       worker_class.constantize
                     rescue
                       @workers[queue]
                     end

      worker_class.new if worker_class
    end

    def queues
      @workers.keys
    end

    def register_worker(queue, clazz)
      if (worker_class = @workers[queue])
        if worker_class.get_shoryuken_options['batch'] == true || clazz.get_shoryuken_options['batch'] == true
          fail ArgumentError, "Could not register #{clazz} for #{queue}, "\
            "because #{worker_class} is already registered for this queue, "\
            "and Shoryuken doesn't support a batchable worker for a queue with multiple workers"
        end
      end

      @workers[queue] = clazz
    end

    def workers(queue)
      [@workers.fetch(queue, [])].flatten
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
shoryuken-5.0.2 lib/shoryuken/default_worker_registry.rb
shoryuken-5.0.1 lib/shoryuken/default_worker_registry.rb
shoryuken-5.0.0 lib/shoryuken/default_worker_registry.rb
shoryuken-4.0.3 lib/shoryuken/default_worker_registry.rb
shoryuken-4.0.2 lib/shoryuken/default_worker_registry.rb
shoryuken-4.0.1 lib/shoryuken/default_worker_registry.rb
shoryuken-4.0.0 lib/shoryuken/default_worker_registry.rb
shoryuken-3.3.1 lib/shoryuken/default_worker_registry.rb
shoryuken-3.3.0 lib/shoryuken/default_worker_registry.rb
shoryuken-3.2.3 lib/shoryuken/default_worker_registry.rb
shoryuken-3.2.2 lib/shoryuken/default_worker_registry.rb
shoryuken-3.2.1 lib/shoryuken/default_worker_registry.rb
shoryuken-3.2.0 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.12 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.11 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.10 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.9 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.8 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.7 lib/shoryuken/default_worker_registry.rb
shoryuken-3.1.6 lib/shoryuken/default_worker_registry.rb