Class: Dionysus::Utils::SidekiqBatchedJobDistributor

Inherits:
Object
  • Object
show all
Defined in:
lib/dionysus/utils/sidekiq_batched_job_distributor.rb

Instance Method Summary collapse

Constructor Details

#initialize(batch_size:, units_count:, time_range_in_seconds:) ⇒ SidekiqBatchedJobDistributor

Returns a new instance of SidekiqBatchedJobDistributor.



7
8
9
10
11
# File 'lib/dionysus/utils/sidekiq_batched_job_distributor.rb', line 7

def initialize(batch_size:, units_count:, time_range_in_seconds:)
  @batch_size = batch_size
  @units_count = units_count
  @time_range_in_seconds = time_range_in_seconds
end

Instance Method Details

#enqueue_batch(job_class, queue, batch_number, *job_arguments) ⇒ Object



21
22
23
# File 'lib/dionysus/utils/sidekiq_batched_job_distributor.rb', line 21

def enqueue_batch(job_class, queue, batch_number, *job_arguments)
  job_class.set(queue: queue).perform_in(batch_number * time_per_batch, *job_arguments)
end

#number_of_batchesObject



13
14
15
# File 'lib/dionysus/utils/sidekiq_batched_job_distributor.rb', line 13

def number_of_batches
  (units_count.to_d / batch_size).ceil
end

#time_per_batchObject



17
18
19
# File 'lib/dionysus/utils/sidekiq_batched_job_distributor.rb', line 17

def time_per_batch
  (time_range_in_seconds.to_d / number_of_batches).floor
end