Ran for less than 5 seconds, finished .
# frozen_string_literal: true
class Maintenance::ImportAgentPortCompaniesTask < MaintenanceTasks::Task
include ArrayHelper
csv_collection(in_batches: 50)
attribute :emails, :string
validates :emails, presence: true, fcm_email_format: true
CSV_COLUMNS = %w[company_guid tree_node_name brand_name crm_sales_id mbo_id mbo_name country_code status
errors].freeze
after_start :prepare_csv_path
after_complete :send_report
after_error :send_report
def process(batch_of_rows)
File.open(csv_path, 'a') do |file|
batch_of_rows.each do |row|
result = AgentPort::RowProcessor.new(row.to_h).call
file.puts build_csv_line(result)
end
end
end
def csv_path
@csv_path ||= Rails.root.join('tmp/import_agent_port_latest.csv').to_s
end
private
def prepare_csv_path
@csv_path = Rails.root.join('tmp', "import_agent_port_#{Time.now.to_i}.csv").to_s
File.write(@csv_path, CSV_COLUMNS.to_csv)
end
def send_report
return unless csv_path && File.exist?(csv_path)
CsvReportMailer.send_report(
recipients: emails_array(emails),
file_path: csv_path,
report_sender: 'Import AgentPort Companies'
).deliver_now
ensure
File.delete(csv_path) if csv_path && File.exist?(csv_path)
end
def build_csv_line(result)
CSV_COLUMNS.map { |col| %w[status errors].include?(col) ? result[col.to_sym] : result[:row][col] }.to_csv
end
end
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for half a minute, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 13 out of 52 items (25%).
Ran for 5 minutes until an error happened .
NoMethodError
private method 'puts' called for nil
app/tasks/maintenance/import_agent_port_companies_task.rb:32:in 'block in Maintenance::ImportAgentPortCompaniesTask#process'
app/tasks/maintenance/import_agent_port_companies_task.rb:30:in 'Array#each'
app/tasks/maintenance/import_agent_port_companies_task.rb:30:in 'Maintenance::ImportAgentPortCompaniesTask#process'
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 1 out of 1 item (100%).
Ran for less than 5 seconds, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for half a minute, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for half a minute, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for less than 20 seconds, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for half a minute, finished .
[FILTERED]
Processed 52 out of 52 items (100%).
Ran for half a minute, finished .
[FILTERED]
Processed 3 out of 3 items (100%).
Ran for less than 5 seconds, finished .
Processed 0 out of 3 items (0%).
Ran for less than 5 seconds until an error happened .
ActiveRecord::RecordInvalid
Validation failed: Name has already been taken
app/services/webhook/adapters/agent_port_sync_adapter.rb:48:in 'block in Webhook::Adapters::AgentPortSyncAdapter#create_company_profile'
app/services/webhook/adapters/agent_port_sync_adapter.rb:47:in 'Array#each'
app/services/webhook/adapters/agent_port_sync_adapter.rb:47:in 'Webhook::Adapters::AgentPortSyncAdapter#create_company_profile'
app/services/webhook/adapters/agent_port_sync_adapter.rb:17:in 'Webhook::Adapters::AgentPortSyncAdapter#call'
app/tasks/maintenance/import_agent_port_companies_task.rb:13:in 'Maintenance::ImportAgentPortCompaniesTask#process'
Processed 0 out of 3 items (0%).
Ran for less than 5 seconds until an error happened .
Utils::Errors::AgentPortApiError
Error calling AgentPortAPI: {"StatusCode":400,"ErrorCode":null,"ErrorDescription":"Provided CompanyGuid is not valid.","Messages":null,"CompanyProfileModel":null} - code:1010
app/services/agent_port/fetch_and_map_company_profile_service.rb:12:in 'AgentPort::FetchAndMapCompanyProfileService#call'
app/services/webhook/adapters/agent_port_sync_adapter.rb:29:in 'Webhook::Adapters::AgentPortSyncAdapter#fetch_and_mapped_data'
app/services/webhook/adapters/agent_port_sync_adapter.rb:47:in 'Webhook::Adapters::AgentPortSyncAdapter#create_company_profile'
app/services/webhook/adapters/agent_port_sync_adapter.rb:17:in 'Webhook::Adapters::AgentPortSyncAdapter#call'
app/tasks/maintenance/import_agent_port_companies_task.rb:13:in 'Maintenance::ImportAgentPortCompaniesTask#process'