Sha256: ca03f4656519d29ebaeed8d8eea46d0293cda50c0e7cf06028ec4b317c1a9c41

Contents?: true

Size: 942 Bytes

Versions: 5

Compression:

Stored size: 942 Bytes

Contents

module Sidekiq
  module Batching
    class Middleware
      def call(worker_class, msg, queue, redis_pool = nil)
        worker_class = worker_class.classify.constantize if worker_class.is_a?(String)
        options = worker_class.get_sidekiq_options

        batch =
          options.keys.include?('batch_size') ||
          options.keys.include?('batch_flush_interval')

        passthrough =
          msg['args'] &&
          msg['args'].is_a?(Array) &&
          msg['args'].try(:first) == true

        if batch && not(passthrough)
          add_to_batch(worker_class, queue, msg, redis_pool)
        else
          if batch && passthrough
            msg['args'].shift
          end
          yield
        end
      end

      private
      def add_to_batch(worker_class, queue, msg, redis_pool = nil)
        Sidekiq::Batching::Batch.new(worker_class.name, queue, redis_pool).add(msg['args'])
        nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sidekiq-batching-0.0.5 lib/sidekiq/batching/middleware.rb
sidekiq-batching-0.0.4 lib/sidekiq/batching/middleware.rb
sidekiq-batching-0.0.3 lib/sidekiq/batching/middleware.rb
sidekiq-batching-0.0.2 lib/sidekiq/batching/middleware.rb
sidekiq-batching-0.0.1 lib/sidekiq/batching/middleware.rb