mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 20:55:44 +02:00
refactoring
This commit is contained in:
parent
aaaae888bf
commit
0d40feb9c0
2 changed files with 26 additions and 19 deletions
|
@ -1,21 +1,28 @@
|
||||||
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
||||||
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
BusinessRegistryContact.delete_all
|
BusinessRegistryContact.delete_all
|
||||||
|
|
||||||
return p 'File not exist!' unless File.exist?(FILE_NAME)
|
return p 'File not exist!' unless File.exist?(FILE_NAME)
|
||||||
|
|
||||||
CSV.foreach(FILE_NAME, headers: true, col_sep: ";") do |row|
|
enumurate_csv_file
|
||||||
name = row[0]
|
end
|
||||||
code = row[1]
|
|
||||||
status = row[5]
|
|
||||||
|
|
||||||
record = BusinessRegistryContact.create({
|
private
|
||||||
name: name,
|
|
||||||
registry_code: code,
|
def enumurate_csv_file
|
||||||
status: status
|
i = 0
|
||||||
})
|
CSV.foreach(FILE_NAME, headers: true, col_sep: ';') do |row|
|
||||||
p "#{record} is successfully created - #{BusinessRegistryContact.count} count"
|
record = BusinessRegistryContact.create(
|
||||||
|
name: row[0],
|
||||||
|
registry_code: row[1],
|
||||||
|
status: row[5]
|
||||||
|
)
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
p "#{record} is successfully created - #{i} count"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ namespace :collect_csv_data do
|
||||||
desc 'Import from csv registry business contact into BusinessRegistryContact model'
|
desc 'Import from csv registry business contact into BusinessRegistryContact model'
|
||||||
|
|
||||||
task business_contacts: :environment do
|
task business_contacts: :environment do
|
||||||
ScanCsvRegistryBusinnesContactsJob.perform_later
|
ScanCsvRegistryBusinnesContactsJob.perform_now
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Add table
Add a link
Reference in a new issue