Guest User

Untitled

a guest
Nov 15th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. User.import_csv(params[:file].path)
  2.  
  3. CsvImportJob.perform_async(URI.parse(params[:file].path))
  4.  
  5. def perform(file_path)
  6.  
  7. User.import_csv(file_path)
  8.  
  9. end
  10.  
  11. » 10 Aug 2015 13:56:26.596 2015-08-10 11:56:25.987726+00:00 app worker.1 - - 3 TID-oqvt6v1d4 ERROR: Actor crashed!
  12. » 10 Aug 2015 13:56:26.596 2015-08-10 11:56:25.987728+00:00 app worker.1 - - Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/RackMultipart20150810-6-14u804c.csv
  13. » 10 Aug 2015 13:56:26.596 2015-08-10 11:56:25.987730+00:00 app worker.1 - - /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/csv.rb:1256:in `initialize'
  14.  
  15. require 'open-uri'
  16.  
  17. class ProcessCsvJob < ActiveJob::Base
  18. queue_as :default
  19.  
  20. def perform(csv_path)
  21. csv_file = open(csv_path,'rb:UTF-8')
  22.  
  23. SmarterCSV.process(csv_file) do |array|
  24. .... code here for processing ...
  25. end
  26. end
  27.  
  28. end
  29.  
  30. def import_csv(file)
  31. CSV.foreach(file.path, headers: true) do |row|
  32. new_user = { email: row[0], password: row[1] }
  33. CsvImportJob.perform_async(new_user)
  34. end
  35. end
Add Comment
Please, Sign In to add comment