Class: AtlasEngine::AddressImporter::ClearRecordsJob

Inherits:
ResumableImportJob show all
Includes:
ImportLogHelper, LogHelper
Defined in:
app/jobs/atlas_engine/address_importer/clear_records_job.rb

Constant Summary collapse

DELETION_BATCH_SIZE =
2000

Constants included from ImportLogHelper

ImportLogHelper::TEST_TIMESTAMP

Instance Method Summary collapse

Methods included from LogHelper

#log_error, #log_info, #log_warn

Methods included from ImportLogHelper

#import_log_error, #import_log_info

Methods inherited from ResumableImportJob

#country_import, #log_final_stats

Methods inherited from AtlasEngine::ApplicationJob

#argument

Instance Method Details

#build_enumerator(params, cursor:) ⇒ Object



11
12
13
# File 'app/jobs/atlas_engine/address_importer/clear_records_job.rb', line 11

def build_enumerator(params, cursor:)
  enumerator_builder.build_times_enumerator(1, cursor: cursor)
end

#clear_recordsObject



20
21
22
23
24
25
26
27
28
# File 'app/jobs/atlas_engine/address_importer/clear_records_job.rb', line 20

def clear_records
  import_log_info(
    country_import: country_import,
    message: "Clearing all records from PostAddress where country_code: #{@country_code}...",
  )
  rows_deleted = delete_rows
  rows_deleted = delete_rows until rows_deleted != DELETION_BATCH_SIZE
  import_log_info(country_import: country_import, message: "PostAddress records cleared.")
end

#delete_rowsObject



30
31
32
33
34
35
36
# File 'app/jobs/atlas_engine/address_importer/clear_records_job.rb', line 30

def delete_rows
  PostAddress.connection.exec_delete(
    "DELETE FROM #{PostAddress.table_name} where country_code = '#{@country_code}' LIMIT #{DELETION_BATCH_SIZE}",
    "DELETE",
    [],
  )
end

#each_iteration(batch, params) ⇒ Object



15
16
17
18
# File 'app/jobs/atlas_engine/address_importer/clear_records_job.rb', line 15

def each_iteration(batch, params)
  @country_code = params[:country_code]
  clear_records
end