Class: Sidekiq::Grouping::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/grouping/middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(worker_class, msg, queue, redis_pool = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sidekiq/grouping/middleware.rb', line 4

def call(worker_class, msg, queue, redis_pool = nil)
  return yield if (defined?(Sidekiq::Testing) && Sidekiq::Testing.inline?)

  worker_class = worker_class.camelize.constantize if worker_class.is_a?(String)
  options = worker_class.get_sidekiq_options

  batch =
    options.key?('batch_flush_size') ||
    options.key?('batch_flush_interval') ||
    options.key?('batch_size')

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

  retrying = msg["failed_at"].present?

  return yield unless batch

  if !(passthrough || retrying)
    add_to_batch(worker_class, queue, msg, redis_pool)
  else
    msg['args'].shift if passthrough
    yield
  end
end