Class: RocketJob::LookupCollection

Inherits:
Mongo::Collection
  • Object
show all
Defined in:
lib/rocket_job/lookup_collection.rb

Defined Under Namespace

Classes: BatchUploader

Instance Method Summary collapse

Instance Method Details

#lookup(id) ⇒ Object

Looks up the value at the specified id. Returns [nil] if no record was found with the supplied id.



21
22
23
# File 'lib/rocket_job/lookup_collection.rb', line 21

def lookup(id)
  find(id: id).first
end

#upload(batch_size: 10_000, &block) ⇒ Object

Rapidly upload individual records in batches.

Operates directly on a Mongo Collection to avoid the overhead of creating Mongoid objects for each and every row.

Example:

lookup_collection(:my_lookup).upload do |io|
  io << {id: 123, data: "first record"}
  io << {id: 124, data: "second record"}
end

input_category(:my_lookup).find(id: 123).first


15
16
17
# File 'lib/rocket_job/lookup_collection.rb', line 15

def upload(batch_size: 10_000, &block)
  BatchUploader.upload(batch_size: batch_size, &block)
end