54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/activerecord-multi-tenant/sidekiq.rb', line 54
def push_bulk_with_tenants(items)
job = items['jobs'].first
return [] unless job 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
|