Class: Dionysus::Producer::Genesis::Streamer::BaseJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/dionysus/producer/genesis/streamer/base_job.rb

Direct Known Subclasses

StandardJob

Constant Summary collapse

ONE_DAY_IN_SECONDS =
60 * 60 * 24
BATCH_SIZE =
1000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enqueue(relation, model_class, topic, number_of_days: 1, batch_size: BATCH_SIZE) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dionysus/producer/genesis/streamer/base_job.rb', line 11

def self.enqueue(relation, model_class, topic, number_of_days: 1, batch_size: BATCH_SIZE)
  distributor = Dionysus::Utils::SidekiqBatchedJobDistributor.new(
    batch_size: batch_size,
    units_count: relation.count,
    time_range_in_seconds: (ONE_DAY_IN_SECONDS * number_of_days)
  )

  relation.in_batches(of: batch_size).lazy.each_with_index do |batch_relation, batch_number|
    distributor.enqueue_batch(
      self,
      Dionysus::Producer.configuration.sidekiq_queue,
      batch_number,
      batch_relation.pluck(model_class.primary_key).sort,
      model_class.to_s,
      topic
    )
  end
end

Instance Method Details

#perform(ids, resource_name, topic) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dionysus/producer/genesis/streamer/base_job.rb', line 30

def perform(ids, resource_name, topic)
  model_class = resource_name.constantize
  primary_key_column = model_class.primary_key

  model_class
    .where(primary_key_column => ids)
    .find_each { |entity| call(entity, topic) }
end