Class: Sidekiq::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-multi-tenant/sidekiq.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.push_bulk_with_tenants(items) ⇒ Object



57
58
59
# File 'lib/activerecord-multi-tenant/sidekiq.rb', line 57

def push_bulk_with_tenants(items)
  new.push_bulk_with_tenants(items)
end

Instance Method Details

#push_bulk_with_tenants(items) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/activerecord-multi-tenant/sidekiq.rb', line 38

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