mirror of
https://github.com/internetee/registry.git
synced 2025-07-25 03:58:27 +02:00
implement asynchronous rake task for collect contact data from csv
This commit is contained in:
parent
cf450d373a
commit
aaaae888bf
5 changed files with 92 additions and 3 deletions
21
app/jobs/scan_csv_registry_businnes_contacts_job.rb
Normal file
21
app/jobs/scan_csv_registry_businnes_contacts_job.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class ScanCsvRegistryBusinnesContactsJob < ApplicationJob
|
||||
FILE_NAME = './ettevotja_rekvisiidid_init.csv'.freeze
|
||||
def perform
|
||||
BusinessRegistryContact.delete_all
|
||||
|
||||
return p 'File not exist!' unless File.exist?(FILE_NAME)
|
||||
|
||||
CSV.foreach(FILE_NAME, headers: true, col_sep: ";") do |row|
|
||||
name = row[0]
|
||||
code = row[1]
|
||||
status = row[5]
|
||||
|
||||
record = BusinessRegistryContact.create({
|
||||
name: name,
|
||||
registry_code: code,
|
||||
status: status
|
||||
})
|
||||
p "#{record} is successfully created - #{BusinessRegistryContact.count} count"
|
||||
end
|
||||
end
|
||||
end
|
2
app/models/business_registry_contact.rb
Normal file
2
app/models/business_registry_contact.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class BusinessRegistryContact < ApplicationRecord
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue