Class: Sidekiq::Form526HistoricalDataExporter::Queuer

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/form526_historical_data_exporter/queuer.rb

Instance Method Summary collapse

Constructor Details

#initialize(chunk_size, batch_size, date_from, date_to = nil) ⇒ Queuer

date_from must be in format MM/DD/YYYY



9
10
11
12
13
14
# File 'lib/sidekiq/form526_historical_data_exporter/queuer.rb', line 9

def initialize(chunk_size, batch_size, date_from, date_to = nil)
  @chunk_size = chunk_size
  @batch_size = batch_size
  @date_from = Date.strptime(date_from, '%m/%d/%Y')
  @date_to = Date.strptime(date_to, '%m/%d/%Y') if date_to.present?
end

Instance Method Details

#chunk_submissionsObject



22
23
24
25
26
27
28
29
# File 'lib/sidekiq/form526_historical_data_exporter/queuer.rb', line 22

def chunk_submissions
  query = if @date_to.present?
            Form526Submission.where('created_at >= ? AND created_at <= ?', @date_from, @date_to)
          else
            Form526Submission.where('created_at >= ?', @date_from)
          end
  query.pluck(:id).each_slice(@chunk_size)
end

#data_job_wrapper(chunk) ⇒ Object



31
32
33
# File 'lib/sidekiq/form526_historical_data_exporter/queuer.rb', line 31

def data_job_wrapper(chunk)
  Form526BackgroundDataJob.perform_async(@batch_size, chunk.first, chunk.last)
end

#exportObject



16
17
18
19
20
# File 'lib/sidekiq/form526_historical_data_exporter/queuer.rb', line 16

def export
  chunk_submissions.each do |chunk|
    data_job_wrapper(chunk)
  end
end