class Sidekiq::Client
Public Class Methods
push_bulk_with_tenants(items)
click to toggle source
# File lib/activerecord-multi-tenant/sidekiq.rb, line 53 def push_bulk_with_tenants(items) new.push_bulk_with_tenants(items) end
Public Instance Methods
push_bulk_with_tenants(items)
click to toggle source
# File lib/activerecord-multi-tenant/sidekiq.rb, line 34 def push_bulk_with_tenants(items) job = items['jobs'].first return [] unless job # no jobs to push raise ArgumentError, "Bulk arguments must be an Array of Hashes: [{ 'args' => [1], 'tenant_id' => 1 }, ...]" if !job.is_a?(Hash) normed = normalize_item(items.except('jobs').merge('args' => [])) payloads = items['jobs'].map do |job| MultiTenant.with(job['tenant_id']) do copy = normed.merge('args' => job['args'], 'jid' => SecureRandom.hex(12), 'enqueued_at' => Time.now.to_f) result = process_single(items['class'], copy) result ? result : nil end end.compact raw_push(payloads) if !payloads.empty? payloads.collect { |payload| payload['jid'] } end