Class: AtlasEngine::AddressImporter::OpenAddress::GeoJsonImportLauncherJob

Inherits:
AtlasEngine::ApplicationJob show all
Extended by:
T::Sig
Includes:
ImportLogHelper
Defined in:
app/jobs/atlas_engine/address_importer/open_address/geo_json_import_launcher_job.rb

Constant Summary

Constants included from ImportLogHelper

ImportLogHelper::TEST_TIMESTAMP

Instance Method Summary collapse

Methods included from ImportLogHelper

#import_log_error, #import_log_info

Methods included from LogHelper

#log_error, #log_info, #log_warn

Methods inherited from AtlasEngine::ApplicationJob

#argument

Instance Method Details

#perform(country_code:, geojson_file_path:, clear_records:, locale:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/jobs/atlas_engine/address_importer/open_address/geo_json_import_launcher_job.rb', line 12

def perform(country_code:, geojson_file_path:, clear_records:, locale:)
  import = CountryImport.create!(country_code: country_code)
  import.start!

  import_log_info(
    country_import: import,
    message: "Starting import",
    additional_params: { file: geojson_file_path },
    notify: true,
  )

  geojson_file_paths = geojson_file_path.split(",")

  geojson_import_jobs = geojson_file_paths.map do |geojson_file_path|
    geojson_job_args = {
      country_code: country_code,
      country_import_id: import.id,
      geojson_file_path: geojson_file_path,
      locale: locale,
    }
    { job_name: GeoJsonImportJob, job_args: geojson_job_args }
  end

  street_backfill_job = {
    job_name: AddressImporter::StreetBackfillJob,
    job_args: { country_code: country_code, country_import_id: import.id },
  }

  if clear_records
    import_log_info(country_import: import, message: "Clearing records before import...")

    AddressImporter::ClearRecordsJob.perform_later(
      country_import_id: import.id,
      country_code: country_code.upcase,
      followed_by: geojson_import_jobs + [street_backfill_job],
    )
  else
    import_log_info(country_import: import, message: "Importing without clearing records...")

    GeoJsonImportJob.perform_later(
      **T.must(geojson_import_jobs.first)[:job_args],
      followed_by: geojson_import_jobs.drop(1) + [street_backfill_job],
    )
  end
rescue StandardError => e
  import_log_error(
    country_import: T.must(import),
    message: "Import failed with #{e.class}",
    additional_params: { error: e },
  )
  import&.interrupt
end