Commit bacb7c56 by Đường Sỹ Hoàng

Fix error handler

parent 86bdeff2
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_10_035904) do ActiveRecord::Schema.define(version: 2019_12_05_082359) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
...@@ -66,8 +66,6 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do ...@@ -66,8 +66,6 @@ ActiveRecord::Schema.define(version: 2019_12_10_035904) do
t.datetime "created_at", precision: 6, null: false t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false
t.string "code" t.string "code"
t.string "location"
t.string "company_name"
end end
create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "user_jobs", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
......
require "csv" require "csv"
namespace :import_job_csv do namespace :job do
desc "Import CSV file into database" desc "Import CSV file into database"
task import_job: :environment do task import_csv: :environment do
CSV.foreach("db/Venjob.csv", headers: true) do |row| CSV.foreach("db/Venjob.csv", headers: true) do |row|
company_params = { company_params = {
email: row["Contact email"], email: row["contact email"],
name: row["Company name"], name: row["company name"],
address: row["Company address"], address: row["company address"],
code: row["Company id"] code: row["company id"]
} }
Company.create!(company_params) Company.create!(company_params)
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_company.log")
import_company_logger.info "Skip #{row}"
next
job_params = { job_params = {
company_id: Company.find_by(code: row["Company id"]).id, company_id: Company.find_by(code: row["company id"]).id,
location: row["Work place"], title: row["name"],
title: row["Name"], description: row["description"],
description: row["Description"], position: row["level"],
position: row["Level"], salary: row["salary"],
salary: row["Salary"], requirement: row["requirement"]
requirement: row["Requirement"]
} }
Job.create!(job_params) Job.create!(job_params)
rescue
import_company_logger = ActiveSupport::Logger.new("log/import_job.log")
import_company_logger.info "Skip #{row}"
next
end end
rescue
import_logger = ActiveSupport::Logger.new("log/import.log")
import_logger.info "Skip #{row}"
next
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment