Maintenance::AddCountriesTask

Source code
# frozen_string_literal: true

class Maintenance::AddCountriesTask < MaintenanceTasks::Task
  include DatadogTrace

  csv_collection

  COUNTRY_CODE_HEADER = 'code'
  COUNTRY_NAME_HEADER = 'name'

  def process(row)
    country_code = row[COUNTRY_CODE_HEADER]

    raise Utils::Errors::MissedCountryCode unless country_code

    country_name = fetch_country_name_from_api(country_code) || row[COUNTRY_NAME_HEADER]

    raise Utils::Errors::WrongCountryCode.new(country_code:) unless country_name

    Country.find_or_create_by(code: country_code).update!(display_name: country_name)
  end

  private

  def fetch_country_name_from_api(code)
    CountryNameFetcherService.new(code).call
  end
end

Previous Runs

Succeeded
#90

Processed 15 out of 15 items (100%).

Ran for less than 5 seconds, finished .