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

Errored
#79

Processed 2 out of 3 items (67%).

Ran for less than 5 seconds until an error happened .

Utils::Errors::MissedCountryCode

Missing country code in row - code:1008

app/tasks/maintenance/add_countries_task.rb:14:in 'Maintenance::AddCountriesTask#process'

Metadata:
user_id
Succeeded
#69

Processed 15 out of 15 items (100%).

Ran for less than 10 seconds, finished .