Ran for less than 10 seconds, finished .
# frozen_string_literal: true
class Maintenance::PopulateMissingCountriesTask < MaintenanceTasks::Task
include DatadogTrace
collection_batch_size(1000)
def collection
TreeNode.where.missing(:gds_profiles)
end
def process(tree_node)
return log_missing_company_guid(tree_node) if tree_node.company_guid.blank?
create_primary_gds_profile(tree_node)
rescue StandardError => e
log_process_error(tree_node, e)
end
delegate :count, to: :collection
private
def log_missing_company_guid(tree_node)
Rails.logger.warn("TreeNode #{tree_node.name}:#{tree_node.id} does not have company_guid")
end
def create_primary_gds_profile(tree_node)
data = fetch_data(tree_node.company_guid)
tree_node.gds_profiles.primary.create!(country_code: extract_country_code(data), primary: true)
end
def log_process_error(tree_node, error)
Rails.logger.warn(
"Error in PopulateMissingCountriesTask, TreeNode #{tree_node.name}:#{tree_node.id}. #{error.message}"
)
end
def fetch_data(company_guid)
Api::AgentPortClient.client.company(company_guid)
end
def extract_country_code(data)
data['CompanyProfileModel']['CompanyIdentity']['CountryCode']
end
end
Processed 11 out of 11 items (100%).
Ran for less than 10 seconds, finished .
Processed 23 out of 23 items (100%).
Ran for half a minute, finished .
Processed 2 out of 2 items (100%).
Ran for less than 5 seconds, finished .
Processed 8 out of 8 items (100%).
Ran for less than 10 seconds, finished .
Processed 0 out of 87 items (0%).
Ran for less than 5 seconds until an error happened .
Api::Errors::BadRequestError
{"StatusCode":400,"ErrorCode":null,"ErrorDescription":"Validation errors were found.","Messages":[{"Field":"companyGuid.String","Message":"A value is required but was not present in the request."}],"CompanyProfileModel":null,"ProfileStatus":null}
lib/api/base_client.rb:43:in 'Api::BaseClient::Agent#handle_errors'
lib/api/base_client.rb:30:in 'block (2 levels) in <class:Agent>'
lib/api/agent_port.rb:6:in 'Api::AgentPort::Wrapper#company'
app/tasks/maintenance/populate_missing_countries_task.rb:9:in 'Maintenance::PopulateMissingCountriesTask#process'
Processed 0 out of 87 items (0%).
Ran for less than 5 seconds until an error happened .
Api::Errors::BadRequestError
{"StatusCode":400,"ErrorCode":null,"ErrorDescription":"Validation errors were found.","Messages":[{"Field":"companyGuid.String","Message":"A value is required but was not present in the request."}],"CompanyProfileModel":null,"ProfileStatus":null}
lib/api/base_client.rb:43:in 'Api::BaseClient::Agent#handle_errors'
lib/api/base_client.rb:30:in 'block (2 levels) in <class:Agent>'
lib/api/agent_port.rb:6:in 'Api::AgentPort::Wrapper#company'
app/tasks/maintenance/populate_missing_countries_task.rb:9:in 'Maintenance::PopulateMissingCountriesTask#process'
Processed 0 out of 87 items (0%).
Ran for less than 5 seconds until an error happened .
Api::Errors::BadRequestError
{"StatusCode":400,"ErrorCode":null,"ErrorDescription":"Validation errors were found.","Messages":[{"Field":"companyGuid.String","Message":"A value is required but was not present in the request."}],"CompanyProfileModel":null,"ProfileStatus":null}
lib/api/base_client.rb:43:in 'Api::BaseClient::Agent#handle_errors'
lib/api/base_client.rb:30:in 'block (2 levels) in <class:Agent>'
lib/api/agent_port.rb:6:in 'Api::AgentPort::Wrapper#company'
app/tasks/maintenance/populate_missing_countries_task.rb:9:in 'Maintenance::PopulateMissingCountriesTask#process'
Processed 11 out of 87 items (13%).
Ran for less than 10 seconds until an error happened .
Api::Errors::BadRequestError
{"StatusCode":400,"ErrorCode":null,"ErrorDescription":"Validation errors were found.","Messages":[{"Field":"companyGuid.String","Message":"A value is required but was not present in the request."}],"CompanyProfileModel":null,"ProfileStatus":null}
lib/api/base_client.rb:43:in 'Api::BaseClient::Agent#handle_errors'
lib/api/base_client.rb:30:in 'block (2 levels) in <class:Agent>'
lib/api/agent_port.rb:6:in 'Api::AgentPort::Wrapper#company'
app/tasks/maintenance/populate_missing_countries_task.rb:9:in 'Maintenance::PopulateMissingCountriesTask#process'