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



73
74
75
# File 'lib/activerecord-multi-tenant/sidekiq.rb', line 73

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

Instance Method Details

#push_bulk_with_tenants(items) ⇒ Object

Raises:

  • (ArgumentError)


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 # 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