Sha256: 6a0f4cfa56066a550dad2bfd9df797ee917542a6901f8ec01c289980a8b349a2

Contents?: true

Size: 723 Bytes

Versions: 5

Compression:

Stored size: 723 Bytes

Contents

require_relative "merge"

class Sidekiq::Merger::Middleware
  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

    merger_enabled = options.key?("merger")

    if merger_enabled && !msg["at"].nil? && msg["at"].to_f > Time.now.to_f
      Sidekiq::Merger::Merge
        .initialize_with_args(worker_class, queue, msg["args"])
        .add(msg["args"], msg["at"])
      false
    else
      msg["args"] = [msg["args"]] unless msg.delete("merged")
      yield(worker_class, msg, queue, redis_pool)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sidekiq-merger-0.0.11 lib/sidekiq/merger/middleware.rb
sidekiq-merger-0.0.10 lib/sidekiq/merger/middleware.rb
sidekiq-merger-0.0.9 lib/sidekiq/merger/middleware.rb
sidekiq-merger-0.0.8 lib/sidekiq/merger/middleware.rb
sidekiq-merger-0.0.7 lib/sidekiq/merger/middleware.rb